LoginSignup
27
21

More than 5 years have passed since last update.

bashでgitのブランチ名を表示させる。

Posted at

Homebrewでinstallしていることが前提の記事が多かったので、
自分用メモに自分がやった手順を記しておきます。

$ git branch

でbranch名を確認することが多い人はやっておくと作業スピードがグングン上がります。

まず、
・git-prompt.sh
・git-completion.bash
この2つのファイルを探します。
Homebrewでinstallした人は

/usr/local/etc/bash_completion.d/

にあるそうですが、自分はなかった。
どうやらHomebrewは使っていないらしい。

探し方は、


sudo find / -name git-prompt.sh
sudo find / -name git-completion.bash

で検索する。どちらも複数ヒットしたけど、
ヤマカンで、

/Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash
/Library/Developer/CommandLineTools/usr/share/git-core/git-prompt.sh

でいくことにした(うまくいった)

次に、vi ~/.bashrcに下記を追記した。

$ vi ~/.bashrc

source /Library/Developer/CommandLineTools/usr/share/git-core/git-prompt.sh
source /Library/Developer/CommandLineTools/usr/share/git-core/git-completion.bash
GIT_PS1_SHOWDIRTYSTATE=true
export PS1='\[\033[32m\]\u@\h\[\033[00m\]:\[\033[34m\]\w\[\033[31m\]$(__git_ps1)\[\033[00m\]\n\$ '

最後に.bashrcから読めるようにするために、


$ vi ~/.bash_profile

source ~/.bashrc

を追記、
.bash_profileと.bashrcにやったことは

https://bottoms-programming.com/archives/terminal-branch-name.html
このサイトを参考にコピペしただけ。

試してみたらあっさりできた。

これで能率アップ間違いなし。

27
21
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
27
21