【VSCode】bash: __git_ps1: command not foundが出たときの対処方法
git-prompt.sh
(gitのプロンプト表示のカスタマイズ用のシェル)、git-completion.bash
(gitコマンド補完用のシェル)を利用しているLinux環境で、VSCodeの結合ターミナル利用時に下記の通り『bash: __git_ps1: command not found』が表示されることがあったので、対象方法を調べてみました。なお、TerraTerm等のターミナルソフトでは、該当のbashのエラーは表示されないことを前提としています。 もし、TerraTerm等のターミナルソフトでも表示される場合は、__git_ps1
はgit-completion.bash
内で定義されているので、git-completion.bash
を読み込めていない、もしくは読み込む前に__git_ps1
を呼び出しているかのいずれかだと思います。
VSCodeの結合ターミナル上の原因
VSCodeのデフォルト設定では、結合ターミナルはログインシェルとしては動作せず、~/.bash_profile
も実行されない。 【参考】 Integrated terminal can't find __git_ps1 · Issue #9484 · microsoft/vscode · GitHub
対処
settings.json
に以下を設定します。terminal.integrated.shell.linux
は利用するシェルを指定します。デフォルトはbashなので、bashを利用する場合は省略可能です。terminal.integrated.shellArgs.linux
は、~/.bash_profile
を実行するための設定です。
"terminal.integrated.shell.linux": "/bin/bash", "terminal.integrated.shellArgs.linux": [ "-l" ]