はじめに
termux上で、ターミナル上にbranch名を表示する方法が見つからなかったので備忘として残しておきます。ちなみにamazon linuxやmacなどでもやることは同じです
gitのinstall
termuxではデフォルトではgit入っていないので、installしておきます
pkg install git
Setting
以下2ファイルのpathを確認します。
find ~/../usr/ -name git-prompt.sh
find ~/../usr/ -name git-completion.bash
おそらく、
/data/data/com.termux/files/home/../usr/etc/bash_completion.d/git-prompt.sh
と
/data/data/com.termux/files/home/../usr/etc/bash_completion.d/git-completion.bash
が返ってくるはずです。
あとは.bash_profileと.bashrcをいじるだけです
~/.bash_profile
に以下を追記
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
~/.bashrc
に以下を追記
source /data/data/com.termux/files/home/../usr/etc/bash_completion.d/git-completion.bash
source /data/data/com.termux/files/home/../usr/etc/bash_completion.d/git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=true
PS1='\[\033[34m\]\w\[\033[31m\]$(__git_ps1)\[\033[00m\]\n\$ '
# サーバ名も先頭に表示させたいときは以下を使う
# PS1='\[\033[32m\]\u@\h\[\033[00m\]:\[\033[34m\]\w\[\033[31m\]$(__git_ps1)\[\033[00m\]\n\$ '
あとは
source ~/.bash_profile
すれば次のような見た目になっているはずです。