2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【bash設定】実行したコマンド成否によってプロンプトの色を出し分ける

Last updated at Posted at 2013-09-22

概要

コマンドの実行に成功したら青色プロンプト、
エラーステータスが返ってきたら赤色プロンプトになるように設定します。

rtakasuke_—terminal—bash—ttys000—_53×8.png

環境

OS
MacOS X 10.8.5

設定

~/.bashrc を編集しましょう
以下を追記します。

~/.bashrc
## prompt
PS1="\`
if [ \$? = 0 ]; then 
    echo \[\e[36m\]; 
else 
    echo \[\e[31m\]; 
fi
\`[\u@\H \w]\[\e[0m\]\n$"

.bashrc を編集したら、設定を反映させます。
$ source ~/.bashrc

2
3
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
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?