Bagaimana Anda Membuat Bash Prompt Mengubah Warna Ketika Masuk Ke Server?

Daftar Isi:

Bagaimana Anda Membuat Bash Prompt Mengubah Warna Ketika Masuk Ke Server?
Bagaimana Anda Membuat Bash Prompt Mengubah Warna Ketika Masuk Ke Server?

Video: Bagaimana Anda Membuat Bash Prompt Mengubah Warna Ketika Masuk Ke Server?

Video: Bagaimana Anda Membuat Bash Prompt Mengubah Warna Ketika Masuk Ke Server?
Video: HANYA DENGAN BERNAFAS POKEMON INI DAPAT MEMBEKUKAN APAPUN!!!! - MEZASE POKEMON MASTER EPISODE 4 - YouTube 2024, April
Anonim
Jika Anda mengakses beberapa server sepanjang hari kerja, maka dapat mengetahui mana yang Anda kerjakan sekilas berdasarkan skema warna bisa sangat berguna. Pos SuperUser Super & Pemutaran Hari ini membantu pembaca mencapai nirvana yang berwarna-warni di lingkungan kerjanya.
Jika Anda mengakses beberapa server sepanjang hari kerja, maka dapat mengetahui mana yang Anda kerjakan sekilas berdasarkan skema warna bisa sangat berguna. Pos SuperUser Super & Pemutaran Hari ini membantu pembaca mencapai nirvana yang berwarna-warni di lingkungan kerjanya.

Sesi Tanya & Jawab Hari ini hadir untuk memberi kami SuperUser - subdivisi Stack Exchange, pengelompokan situs web Q & A berbasis komunitas.

Pertanyaan

SuperUser reader nitins ingin tahu cara membuat warna perubahan Bash Prompt saat masuk ke server:

Is there a way to make the Bash Prompt dynamic so that it changes color when I am logged into a server? I want the color to be green when using my own personal system, but change to red whenever I am connected to servers. I have a huge number of servers that I access and do not want to have to put a different .bashrc on each and every one of them.

Bagaimana Anda membuat warna Bash Prompt berubah saat masuk ke server?

Jawabannya

Kontributor SuperUser Matei David memiliki jawabannya untuk kami:

Remote Bash Prompts are set by the remote ~/.bashrc, so you will still need to copy it to the remote servers. However, you can use a single ~/.bashrc for all hosts and set the Bash Prompt color based on the host name:

Image
Image

Notes

  • Do not set PS1 if it is not already set (i.e. if the shell is not interactive). Testing to see if PS1 is “non-empty” is a very common way to find out if the shell is interactive and you do not want to confuse programs that do that (arguably, a more accurate test is checking to see if $- contains i).
  • If you want this code to run when logging into a remote server, you should have one of the profile files always source ~/.bashrc (I am assuming you know that).
  • In PS1, the escape codes must be enclosed in […].
  • [033[m resets the foreground and background to their defaults, so here :w appears in the terminal foreground/background.
  • [033[48;5;XXXm33[38;5;YYYm sets the background/foreground to XXX/YYY.
  • For a script that dumps the available colors, try colortest.
  • To check and see what the Bash Prompt would look like, use: echo -e “<33[48;5;16m33[38;5;196mhost33[m:dir>$ “

Memiliki sesuatu untuk ditambahkan ke penjelasan? Bicaralah di komentar. Ingin membaca lebih banyak jawaban dari pengguna Stack Exchange yang paham teknologi lainnya? Lihat diskusi lengkap di sini.

Kredit Gambar: Emx (Wikipedia)

Direkomendasikan: