Gitの補完やら、ブランチ名表示やらをbashでしようとしたらエラーが出る


まず、以下の記述を ~/.bashrc に記述する。

source /usr/local/etc/bash_completion.d/git-prompt.sh
source /usr/local/etc/bash_completion.d/git-completion.bash
GIT_PS1_SHOWDIRTYSTATE=true
export PS1='\[\033[32m\]\u@\h\[\033[00m\]:\[\033[34m\]\w\[\033[31m\]$(__git_ps1)\[\033[00m\]\$ '

コンソールを再起動または、 source ~/.bashrc すると反映されるが、
ここで自分は以下のエラーが出てできなかった。

-bash: /usr/local/etc/bash_completion.d/git-prompt.sh: No such file or directory
-bash: /usr/local/etc/bash_completion.d/git-completion.bash: No such file or directory

// (このエラーも出た)
__git_ps1: command not found

そもそも、便利機能のシェルがないぜっ、ってことみたい。
(brewでgitを入れている人は問題ない?)

ってことで便利機能のシェルをダウンロードしてくることにした。
wgetなりcurlなりで以下の場所からダウンロードする。

// git-prompt.sh のダウンロード
wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh  
// git-completion.sh のダウンロード
wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash

ダウンロードした二つのファイルを以下に保存。

/usr/local/etc/bash_completion.d/

これでOKでした。