LoginSignup
7
6

More than 5 years have passed since last update.

コマンド打つときの左の[user@host ~] $ みたいなのに色をつける

Last updated at Posted at 2013-09-10

追記 色々と修正。今度こそ大丈夫のはず。

コマンド打つときの左側にある部分。あれはPS1(primary prompt string)っていうらしいんですが単純に「プロンプト」だけでもOKっぽいですね。よくわからん。

さて、ここに色ついてると便利ですよね。コマンドの結果がズラズラ―っと出て何行ぐらい流れたかわからない時も画面内に収まる程度ならすぐにわかりますし。 なので色を付けてみました。

~/.bash_profile
# Set Prompt String color
lc='\[\e[1;' # lead-in character
RED=${lc}31m;
GREEN=${lc}32m
PURPLE=${lc}35m
RC=${lc}0m # reset character

if [ "$USER" = "root" ]
then
pc=$RED
else
pc=$GREEN
fi

PS1="${pc}\]\u@\h \W\\$ ${RC}\]"

VPS上のホスト名は sudo hostname myhostname で好きに変えれば良いっぽい。

参考

デモ対策:プロンプトを短くするやり方メモ - 情報科学屋さんを目指す人のメモ(FC2ブログ版)
http://did2.blog64.fc2.com/blog-entry-249.html

bashプロンプトに色を付ける|set color of prompt - sppr’s notes
http://d.hatena.ne.jp/sppr/20090117/1232199271

コマンドラインの左側の部分に名前はついてますか? - QA@IT
http://qa.atmarkit.co.jp/q/2993

Overwraping lines when using ssh by osx terminal - Super User
http://superuser.com/questions/648296/overwraping-lines-when-using-ssh-by-osx-terminal/648343?noredirect=1#648343

| Red Hat
http://www.redhat.com/advice/tips/rhce/prompt.html

7
6
1

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
6