git-bashプロンプトを設定する

/ Bash

下記を.bashrcの末尾に下記をコピー&ペーストで追記。

if [ -f /etc/bash_completion.d/git-prompt ]; then
    export PS1='\[\033[01;32m\]\u@\h\[\033[01;33m\] \w$(__git_ps1) \n\[\033[01;34m\]\$\[\033[00m\] '
else
    export PS1='\[\033[01;32m\]\u@\h\[\033[01;33m\] \w \n\[\033[01;34m\]\$\[\033[00m\] '
fi

プロンプトが下記のようになる。色付き。

user@user-Inspiron-3268 /mnt/ssd/linux (android14-6.1-lts)
$

gitの配下にいる場合はブランチやタグなどの情報がかっこ内に表示される。