git跟bash的integration

2021-08-08
1分鐘閱讀

簡單紀錄下gitbash的integration,包含自動補全跟git folder中的狀態提示

下載

先到git的repo裡下載git-completion.bashgit-prompt.sh,放到加目錄中,不想看到他的話,可以檔名前加.隱藏起來

  • git-completion.bash為自動補全
  • git-prompt.sh為提示integration

git: https://github.com/git/git/tree/master/contrib/completion

修改bash source file

在ubuntu中,我習慣我自己改的都寫在~/.bash_aliases中,這就依個人喜好寫在~/.bashrc也可

加入如下東西

# git integration
source ~/.git-completion.bash
source ~/.git-prompt.sh
export GIT_PS1_SHOWDIRTYSTATE=1
export PS1='\[\033[01;32m\]\u@\H:\w$(__git_ps1 " (%s)")\$ \[\033[00m\]'

  • 一二行分別source入檔案
  • GIT_PS1_SHOWDIRTYSTATE=1,可顯示unstaged(*) 跟 staged(+)的狀態

In addition, if you set GIT_PS1_SHOWDIRTYSTATE to a nonempty value, unstaged (*) and staged (+) changes will be shown next to the branch name. You can configure this per-repository with the bash.showDirtyState variable, which defaults to true once

  • PS1=...,就設定你的prompt要長怎樣,更客製化可以借助這網站

.bashrc generator: http://bashrcgenerator.com/

author:   allmwh
commit:   99c8743
comment:   git-integration
lastmod:   2021-08-08 22:02:25
Avatar
allmwh 好油哦,配口水... 紀錄一些生活的事
comments powered by Disqus