LoginSignup
1
1

More than 5 years have passed since last update.

AmazonLinuxのbashプロンプトにgitのブランチ名を表示させてみた

Posted at

今いるディレクトリの git のブランチ名をプロンプトに表示する - Qiita

これにしたがって、AmazonLinuxのbashプロンプトにgitのブランチ名を表示させてみた。

あと、AmazonLinuxのプロンプトって標準では、[ec2-user@ip-12-34-56-78]とかでるので、番号じゃどのインスタンスか間違えやすいので、次の設定もした。

Linux インスタンスのホスト名の変更 - Amazon Elastic Compute Cloud

任意のサーバー名を考えて突っ込む。

sudo sh -c 'echo "export NICKNAME=webserver" > /etc/profile.d/prompt.sh'

あとは、自分のGitに入っている、git-prompt.shの場所を調べる。僕の場合は/usr/share/doc/git-2.1.0/contrib/completion/git-prompt.shだったので、GIT_CONTRIB_DIRに突っ込む。

~/bashrc
# Prompt
gitps1="true"
GIT_CONTRIB_DIR=/usr/share/doc/git-2.1.0/contrib
if [ -r ${GIT_CONTRIB_DIR}/completion/git-prompt.sh ]; then
  . ${GIT_CONTRIB_DIR}/completion/git-prompt.sh
  gitps1="__git_ps1"
fi

export PS1='\[\e[1;31m\][\u@${NICKNAME} \W$(${gitps1})]\$\[\e[m\] '

これで、どこのインスタンスのどのブランチにいるのかを間違えないで済むので素敵です。

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