- GitHub / git / git / blob / master / contrib / completion / git-prompt.sh
- 技術メモ / 2011-09-01: bash-git-completion、__git_ps1のオプションを設定して様々な情報を表示する
- Qiita
- varmil / 2016-08-09: 「Git補完をしらない」「git statusを1日100回は使う」そんなあなたに朗報【git-completionとgit-prompt】
- fujieda / 2017-10-21: Cygwinでgit-prompt.shが遅い 要確認
git-prompt.sh の公式なコメントとしては ~/.git-prompt.sh にコピーして source ~/.git-prompt.sh せよとある。
Ubuntu の場合は、git パッケージに含まれてて、bash_completion を入れてると自動的に読み込まれているので不要。
Cygwin の場合は、少なくとも 2018-03-27 現在においては、git-prompt.sh を含んでいるパッケージが存在しないので、上記 git の公式リポジトリから拾ってくるしかない。
Cygwin の場合はとりあえず bash-completion を入れた上で以下のようにして /etc/bash_completion.d に放り込んどけばよいだろう。
Ubuntu の場合は、git パッケージに含まれてて、bash_completion を入れてると自動的に読み込まれているので不要。
Cygwin の場合は、少なくとも 2018-03-27 現在においては、git-prompt.sh を含んでいるパッケージが存在しないので、上記 git の公式リポジトリから拾ってくるしかない。
Cygwin の場合はとりあえず bash-completion を入れた上で以下のようにして /etc/bash_completion.d に放り込んどけばよいだろう。
( mkdir -p /etc/bash_completion.d; cd /etc/bash_completion.d; wget https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh )
うちの bash の設定は、shell - prompt#bash-current
bash の場合 PS1 に以下のように __git_ps1 を埋めておけば良い。
GIT_PS1_SHOWCOLORHINTS によるカラー化を有効にするには以下のようにする。
あとは後述のカスタマイズに関する設定を以下のような感じでしておく
bash の場合 PS1 に以下のように __git_ps1 を埋めておけば良い。
PS1='... $(__git_ps1 "\n(%s)") ...'書式を与えない場合は " (%s)" がデフォルトの書式
GIT_PS1_SHOWCOLORHINTS によるカラー化を有効にするには以下のようにする。
function gen_ps1 () { __git_ps1 'PRE' 'POST' 'FORMAT' } PROMPT_COMMAND='gen_ps1'上記で、もし __git_ps1 に与えるパラメータが
__git_ps1 '\u@\h: \w' '\n$ ' '\n(%s)'であれば PROMPT は以下のようになる
user@host: ~/git (master) $
あとは後述のカスタマイズに関する設定を以下のような感じでしておく
GIT_PS1_DESCRIBE_STYLE=default GIT_PS1_SHOWCOLORHINTS=1 GIT_PS1_SHOWDIRTYSTATE=1 GIT_PS1_SHOWSTASHSTATE=1 GIT_PS1_SHOWUNTRACKEDFILES=1 GIT_PS1_SHOWUPSTREAM=auto # GIT_PS1_DESCRIBE_STYLE # GIT_PS1_HIDE_IF_PWD_IGNORED
ちょっと不正確かもしれないけど多分以下のような感じ
表示 | 状態 | 条件 |
---|---|---|
REBASE-i | rebase 中 merge 待ち? (interactive) | test -f .git/rebase-merge/interactive |
REBASE-m | rebase 中 merge 待ち? (non interactive) | test -d .git/rebase-merge/ |
REBASE | rebase 中 apply 待ち? | test -f .git/rebase-apply/rebasing |
AM | am 中 apply 待ち? | test -f .git/rebase-apply/applying |
AM/REBASE | am/rebase 中 apply 待ち? | test -d .git/rebase-apply/ |
MERGING | merge 中 | test -f .git/MERGE_HEAD |
CHERRY-PICKING | cherry-pick 中 | test -f .git/CHERRY_PICK_HEAD |
REVERTING | revert 中 | test -f .git/REVERT_HEAD |
BISECTING | bicect 中 | test -f .git/BISECT_LOG |
以下の環境変数を設定すると、動作をカスタマイズ出来る。
対応する git config variable が存在する場合は、git config によりリポジトリ毎に設定を上書き出来る。
対応する git config variable が存在する場合は、git config によりリポジトリ毎に設定を上書き出来る。
dirty state (tracked file の更新の有無と staged の状況) の表示
git config variable: bash.showDirtyState
available value: nonempty な任意の文字列
git config variable: bash.showDirtyState
available value: nonempty な任意の文字列
表示 | 状態 |
---|---|
* | unstaged |
+ | staged |
# | current branch does not have any commits yet (?) |
stash state 表示
git config variable: ?
available value: nonempty な任意の文字列
git config variable: ?
available value: nonempty な任意の文字列
表示 | 状態 |
---|---|
$ | something is stashed |
untracked files の有無を表示する
git config variable: ?
available value: nonempty な任意の文字列
git config variable: ?
available value: nonempty な任意の文字列
表示 | 状態 |
---|---|
% | untracked files が存在 |
HEAD と upstream を比較する
git config variable: bash.showUpstream
available value: スペースで区切った以下の値
git config variable: bash.showUpstream
available value: スペースで区切った以下の値
value | 意味 |
---|---|
auto | auto |
verbose | show number of commits ahead/behind (+/-) upstream |
name | if verbose, then also show the upstream abbrev name |
legacy | don't use the '--count' option available in recent versions of git-rev-list |
git | always compare HEAD to @{upstream} |
svn | always compare HEAD to your SVN upstream |
表示 | 状態 |
---|---|
< | you are ahead |
> | you are behind |
<> | you have diverged |
= | there is no difference |
branch name 間の区切り文字を変更できる。
git config variable: ?
available value: 任意の文字列 (default: " ")
git config variable: ?
available value: 任意の文字列 (default: " ")
detatched HEAD として checkout された commit の詳細情報を表示
git config variable: ?
available value: 以下の値
git config variable: ?
available value: 以下の値
value | 意味 |
---|---|
contains | relative to newer annotated tag (v1.6.3.2~35) |
branch | relative to newer tag or branch (master~4) |
describe | relative to older annotated tag (v1.6.3.1-13-gdd42c2f) |
tag | relative to any older tag (v1.6.3.1-13-gdd42c2f) |
default | exactly matching tag |
dirty state をカラー表示する
git config variable: ?
available value: nonempty な任意の文字列
git config variable: ?
available value: nonempty な任意の文字列
current directory が .gitignore に設定されていた場合、表示を抑制する
git config variable: bash.hideIfPwdIgnored
available value: nonempty な任意の文字列
git config variable: bash.hideIfPwdIgnored
available value: nonempty な任意の文字列
タグ
コメントをかく