LoginSignup
10
5

More than 5 years have passed since last update.

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

Posted at

まず、以下の記述を ~/.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でした。

10
5
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
10
5