|
8 | 8 | # To enable:
|
9 | 9 | #
|
10 | 10 | # 1) Copy this file to somewhere (e.g. ~/.git-prompt.sh).
|
11 |
| -# 2) Add the following line to your .bashrc/.zshrc: |
12 |
| -# source ~/.git-prompt.sh |
| 11 | +# 2) Add the following line to your .bashrc/.zshrc/.profile: |
| 12 | +# . ~/.git-prompt.sh # dot path/to/this-file |
13 | 13 | # 3a) Change your PS1 to call __git_ps1 as
|
14 | 14 | # command-substitution:
|
15 | 15 | # Bash: PS1='[\u@\h \W$(__git_ps1 " (%s)")]\$ '
|
|
30 | 30 | # Optionally, you can supply a third argument with a printf
|
31 | 31 | # format string to finetune the output of the branch status
|
32 | 32 | #
|
| 33 | +# See notes below about compatibility with other shells. |
| 34 | +# |
33 | 35 | # The repository status will be displayed only if you are currently in a
|
34 | 36 | # git repository. The %s token is the placeholder for the shown status.
|
35 | 37 | #
|
|
106 | 108 | # directory is set up to be ignored by git, then set
|
107 | 109 | # GIT_PS1_HIDE_IF_PWD_IGNORED to a nonempty value. Override this on the
|
108 | 110 | # repository level by setting bash.hideIfPwdIgnored to "false".
|
| 111 | +# |
| 112 | +# Compatibility with other shells (beyond bash/zsh): |
| 113 | +# |
| 114 | +# We require posix-ish shell plus "local" support, which is most |
| 115 | +# shells (even pdksh), but excluding ksh93 (because no "local"). |
| 116 | +# |
| 117 | +# Prompt integration might differ between shells, but the gist is |
| 118 | +# to load it once on shell init with '. path/to/git-prompt.sh', |
| 119 | +# set GIT_PS1* vars once as needed, and either place $(__git_ps1..) |
| 120 | +# inside PS1 once (0/1 args), or, before each prompt is displayed, |
| 121 | +# call __git_ps1 (2/3 args) which sets PS1 with the status embedded. |
| 122 | +# |
| 123 | +# Many shells support the 1st method of command substitution, |
| 124 | +# though some might need to first enable cmd substitution in PS1. |
| 125 | +# |
| 126 | +# When using colors, each escape sequence is wrapped between byte |
| 127 | +# values 1 and 2 (control chars SOH, STX, respectively), which are |
| 128 | +# invisible at the output, but for bash/readline they mark 0-width |
| 129 | +# strings (SGR color sequences) when calculating the on-screen |
| 130 | +# prompt width, to maintain correct input editing at the prompt. |
| 131 | +# |
| 132 | +# Currently there's no support for different markers, so if editing |
| 133 | +# behaves weird when using colors in __git_ps1, then the solution |
| 134 | +# is either to disable colors, or, in some shells which only care |
| 135 | +# about the width of the last prompt line (e.g. busybox-ash), |
| 136 | +# ensure the git output is not at the last line, maybe like so: |
| 137 | +# PS1='\n\w \u@\h$(__git_ps1 " (%s)")\n\$ ' |
109 | 138 |
|
110 | 139 | # check whether printf supports -v
|
111 | 140 | __git_printf_supports_v=
|
|
0 commit comments