LoginSignup
7
7

More than 5 years have passed since last update.

環境に応じてシェルのプロンプトの色を変えるなど

Posted at

~/.bashrc でも /etc/profile でも /etc/profile.d/myprompt.sh でもいいんだけど、こんな風に書いておくと、ホスト名が honban の時だけプロンプトが赤くなる。

PS1="[\u@\h \W]\$ "
if [ "$(hostname)" == "honban" ]; then
  PS1="\[\033[31m\]${PS1}\[\033[0m\]"
fi

最初の行の PS1 をどうするかは、echo $PS1 するとかして判断してほしい。

if の中の条件はなんでもいい。例えば Amazon EC2 で stage タグが production の時だけ赤くするとか、業務時間外だと赤くなるとか。

参考

7
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
7