0
0

More than 3 years have passed since last update.

termuxでgitのbranch名表示できるようにする

Last updated at Posted at 2020-01-13

はじめに

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

すれば次のような見た目になっているはずです。

Screenshot_20200113-150919.png

0
0
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
0
0