update and rename git-prompt.sh
parent
3377d6d042
commit
f8ce39d963
|
@ -70,6 +70,15 @@
|
||||||
# state symbols by setting GIT_PS1_STATESEPARATOR. The default separator
|
# state symbols by setting GIT_PS1_STATESEPARATOR. The default separator
|
||||||
# is SP.
|
# is SP.
|
||||||
#
|
#
|
||||||
|
# When there is an in-progress operation such as a merge, rebase,
|
||||||
|
# revert, cherry-pick, or bisect, the prompt will include information
|
||||||
|
# related to the operation, often in the form "|<OPERATION-NAME>".
|
||||||
|
#
|
||||||
|
# When the repository has a sparse-checkout, a notification of the form
|
||||||
|
# "|SPARSE" will be included in the prompt. This can be shortened to a
|
||||||
|
# single '?' character by setting GIT_PS1_COMPRESSSPARSESTATE, or omitted
|
||||||
|
# by setting GIT_PS1_OMITSPARSESTATE.
|
||||||
|
#
|
||||||
# By default, __git_ps1 will compare HEAD to your SVN upstream if it can
|
# By default, __git_ps1 will compare HEAD to your SVN upstream if it can
|
||||||
# find one, or @{upstream} otherwise. Once you have set
|
# find one, or @{upstream} otherwise. Once you have set
|
||||||
# GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by
|
# GIT_PS1_SHOWUPSTREAM, you can override it on a per-repository basis by
|
||||||
|
@ -88,7 +97,8 @@
|
||||||
# If you would like a colored hint about the current dirty state, set
|
# If you would like a colored hint about the current dirty state, set
|
||||||
# GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
|
# GIT_PS1_SHOWCOLORHINTS to a nonempty value. The colors are based on
|
||||||
# the colored output of "git status -sb" and are available only when
|
# the colored output of "git status -sb" and are available only when
|
||||||
# using __git_ps1 for PROMPT_COMMAND or precmd.
|
# using __git_ps1 for PROMPT_COMMAND or precmd in Bash,
|
||||||
|
# but always available in Zsh.
|
||||||
#
|
#
|
||||||
# If you would like __git_ps1 to do nothing in the case when the current
|
# If you would like __git_ps1 to do nothing in the case when the current
|
||||||
# directory is set up to be ignored by git, then set
|
# directory is set up to be ignored by git, then set
|
||||||
|
@ -128,6 +138,7 @@ __git_ps1_show_upstream ()
|
||||||
done <<< "$output"
|
done <<< "$output"
|
||||||
|
|
||||||
# parse configuration values
|
# parse configuration values
|
||||||
|
local option
|
||||||
for option in ${GIT_PS1_SHOWUPSTREAM}; do
|
for option in ${GIT_PS1_SHOWUPSTREAM}; do
|
||||||
case "$option" in
|
case "$option" in
|
||||||
git|svn) upstream="$option" ;;
|
git|svn) upstream="$option" ;;
|
||||||
|
@ -278,11 +289,43 @@ __git_ps1_colorize_gitstring ()
|
||||||
r="$c_clear$r"
|
r="$c_clear$r"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Helper function to read the first line of a file into a variable.
|
||||||
|
# __git_eread requires 2 arguments, the file path and the name of the
|
||||||
|
# variable, in that order.
|
||||||
__git_eread ()
|
__git_eread ()
|
||||||
{
|
{
|
||||||
local f="$1"
|
test -r "$1" && IFS=$'\r\n' read "$2" <"$1"
|
||||||
shift
|
}
|
||||||
test -r "$f" && read "$@" <"$f"
|
|
||||||
|
# see if a cherry-pick or revert is in progress, if the user has committed a
|
||||||
|
# conflict resolution with 'git commit' in the middle of a sequence of picks or
|
||||||
|
# reverts then CHERRY_PICK_HEAD/REVERT_HEAD will not exist so we have to read
|
||||||
|
# the todo file.
|
||||||
|
__git_sequencer_status ()
|
||||||
|
{
|
||||||
|
local todo
|
||||||
|
if test -f "$g/CHERRY_PICK_HEAD"
|
||||||
|
then
|
||||||
|
r="|CHERRY-PICKING"
|
||||||
|
return 0;
|
||||||
|
elif test -f "$g/REVERT_HEAD"
|
||||||
|
then
|
||||||
|
r="|REVERTING"
|
||||||
|
return 0;
|
||||||
|
elif __git_eread "$g/sequencer/todo" todo
|
||||||
|
then
|
||||||
|
case "$todo" in
|
||||||
|
p[\ \ ]|pick[\ \ ]*)
|
||||||
|
r="|CHERRY-PICKING"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
revert[\ \ ]*)
|
||||||
|
r="|REVERTING"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
|
# __git_ps1 accepts 0 or 1 arguments (i.e., format string)
|
||||||
|
@ -389,6 +432,13 @@ __git_ps1 ()
|
||||||
return $exit
|
return $exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
local sparse=""
|
||||||
|
if [ -z "${GIT_PS1_COMPRESSSPARSESTATE}" ] &&
|
||||||
|
[ -z "${GIT_PS1_OMITSPARSESTATE}" ] &&
|
||||||
|
[ "$(git config --bool core.sparseCheckout)" = "true" ]; then
|
||||||
|
sparse="|SPARSE"
|
||||||
|
fi
|
||||||
|
|
||||||
local r=""
|
local r=""
|
||||||
local b=""
|
local b=""
|
||||||
local step=""
|
local step=""
|
||||||
|
@ -397,11 +447,7 @@ __git_ps1 ()
|
||||||
__git_eread "$g/rebase-merge/head-name" b
|
__git_eread "$g/rebase-merge/head-name" b
|
||||||
__git_eread "$g/rebase-merge/msgnum" step
|
__git_eread "$g/rebase-merge/msgnum" step
|
||||||
__git_eread "$g/rebase-merge/end" total
|
__git_eread "$g/rebase-merge/end" total
|
||||||
if [ -f "$g/rebase-merge/interactive" ]; then
|
r="|REBASE"
|
||||||
r="|REBASE-i"
|
|
||||||
else
|
|
||||||
r="|REBASE-m"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
if [ -d "$g/rebase-apply" ]; then
|
if [ -d "$g/rebase-apply" ]; then
|
||||||
__git_eread "$g/rebase-apply/next" step
|
__git_eread "$g/rebase-apply/next" step
|
||||||
|
@ -416,10 +462,8 @@ __git_ps1 ()
|
||||||
fi
|
fi
|
||||||
elif [ -f "$g/MERGE_HEAD" ]; then
|
elif [ -f "$g/MERGE_HEAD" ]; then
|
||||||
r="|MERGING"
|
r="|MERGING"
|
||||||
elif [ -f "$g/CHERRY_PICK_HEAD" ]; then
|
elif __git_sequencer_status; then
|
||||||
r="|CHERRY-PICKING"
|
:
|
||||||
elif [ -f "$g/REVERT_HEAD" ]; then
|
|
||||||
r="|REVERTING"
|
|
||||||
elif [ -f "$g/BISECT_LOG" ]; then
|
elif [ -f "$g/BISECT_LOG" ]; then
|
||||||
r="|BISECTING"
|
r="|BISECTING"
|
||||||
fi
|
fi
|
||||||
|
@ -466,6 +510,7 @@ __git_ps1 ()
|
||||||
local i=""
|
local i=""
|
||||||
local s=""
|
local s=""
|
||||||
local u=""
|
local u=""
|
||||||
|
local h=""
|
||||||
local c=""
|
local c=""
|
||||||
local p=""
|
local p=""
|
||||||
|
|
||||||
|
@ -498,6 +543,11 @@ __git_ps1 ()
|
||||||
u="%${ZSH_VERSION+%}"
|
u="%${ZSH_VERSION+%}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -n "${GIT_PS1_COMPRESSSPARSESTATE}" ] &&
|
||||||
|
[ "$(git config --bool core.sparseCheckout)" = "true" ]; then
|
||||||
|
h="?"
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
|
if [ -n "${GIT_PS1_SHOWUPSTREAM-}" ]; then
|
||||||
__git_ps1_show_upstream
|
__git_ps1_show_upstream
|
||||||
fi
|
fi
|
||||||
|
@ -505,9 +555,11 @@ __git_ps1 ()
|
||||||
|
|
||||||
local z="${GIT_PS1_STATESEPARATOR-" "}"
|
local z="${GIT_PS1_STATESEPARATOR-" "}"
|
||||||
|
|
||||||
# NO color option unless in PROMPT_COMMAND mode
|
# NO color option unless in PROMPT_COMMAND mode or it's Zsh
|
||||||
if [ $pcmode = yes ] && [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
|
if [ -n "${GIT_PS1_SHOWCOLORHINTS-}" ]; then
|
||||||
__git_ps1_colorize_gitstring
|
if [ $pcmode = yes ] || [ -n "${ZSH_VERSION-}" ]; then
|
||||||
|
__git_ps1_colorize_gitstring
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
b=${b##refs/heads/}
|
b=${b##refs/heads/}
|
||||||
|
@ -516,8 +568,8 @@ __git_ps1 ()
|
||||||
b="\${__git_ps1_branch_name}"
|
b="\${__git_ps1_branch_name}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local f="$w$i$s$u"
|
local f="$h$w$i$s$u"
|
||||||
local gitstring="$c$b${f:+$z$f}$r$p"
|
local gitstring="$c$b${f:+$z$f}${sparse}$r$p"
|
||||||
|
|
||||||
if [ $pcmode = yes ]; then
|
if [ $pcmode = yes ]; then
|
||||||
if [ "${__git_printf_supports_v-}" != yes ]; then
|
if [ "${__git_printf_supports_v-}" != yes ]; then
|
Reference in New Issue