徒然なるままに

学習メモがメインです

-bash: __git_ps1: command not foundの対処法

下記のコマンドを入力後にエラーになったので、その対処法を書きます。

export PS1='\[\033[32m\]\u@\h\[\033[00m\]:\[\033[34m\]\w\[\033[31m\]$(__git_ps1)\[\033[00m\]\n\$ '

環境

  • macOS 10.14.6
  • GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18) Copyright (C) 2007 Free Software Foundation, Inc.

__git_ps1とは

参考記事:
「Git補完をしらない」「git statusを1日100回は使う」そんなあなたに朗報【git-completionとgit-prompt】 - Qiita

git-prompt.shが入っているか確認。

/usr/local/etc/bash_completion.d/配下に置くことが多い模様なのでディレクトリを確認。

ls -l /usr/local/etc/bash_completion.d/

確認したが存在しないのでダウンロード。(ついでにgit-completion.bashもDLします。)

ダウンロード/環境変数設定

 $ pwd
/usr/local/etc/bash_completion.d/

curl -O https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
curl -O https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash

chmod a+x git*.* #実行権限を付与

ls -l $PWD/git*.* | awk '{print "source "$9}' >> $HOME/.bashrc

. ~$HOME/.bashrc

結果

f:id:tagoaskubeya:20200210000050p:plain

余談(PS1の設定値を知ったきっかけ)

モブプロする機会があり、筆者がドライバーになってました。
「ターミナルが見辛いので、あるコマンドを入力欲しい。」

もともとのターミナルの表示はこれ。 うわ、私のターミナルダサすぎ...?

PS1='[\u@\h \w]\$ '

カッコいいターミナルの表示を調べられていなかったので、ちょうどいい機会でした。