LoginSignup
1
1

More than 5 years have passed since last update.

[linux]プロンプトのカスタマイズ

Posted at

メモ
linuxのコマンドプロンプトの表示を環境によって変えたかったり、gitのブランチ名を表示させたかったりしたので
変更の仕方をメモする

▼ 現状のプロンプトの設定を確認

echo $PS1

▼ 表示内容の調整

ユーザー名[環境名]@今いる階層(gitブランチ名)$ 

▼ gitブランチ名表示処理を用意

$ cd ~
$ vi .git_branch_name.sh
function git_branch_name {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}

▼ .bashrcに追記

source ~/.git_branch_name.sh
export PS1='\[\033[32m\]\u[環境名]\[\033[31m\]@\[\033[32m\]\w\[\033[31m\]$(git_branch_name)\[\033[00m\]\$ '
1
1
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
1
1