git-prompt: replace [[...]] with standard code
The existing [[...]] tests were either already valid as standard [...] tests, or only required minimal retouch: Notes: - [[...]] doesn't do field splitting and glob expansion, so $var or $(cmd...) don't need quoting, but [... does need quotes. - [[ X == Y ]] when Y is a string is same as [ X = Y ], but if Y is a pattern, then we need: case X in Y)... ; esac . - [[ ... && ... ]] was replaced with [ ... ] && [ ... ] . - [[ -o <zsh-option> ]] requires [[...]], so put it in "eval" and only eval it in zsh, so other shells would not abort on syntax error (posix says [[ has unspecified results, shells allowed to reject it) - ((x++)) was changed into x=$((x+1)) (yeah, not [[...]] ...) Shells which accepted the previous forms: - bash, zsh, ksh93, mksh, openbsd sh, pdksh. Shells which didn't, and now can process it: - dash, free/net bsd sh, busybox-ash, Schily Bourne sh, yash. Signed-off-by: Avi Halachmi (:avih) <avihpit@yahoo.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
f2e264e43f
commit
fe445a1026
@ -126,7 +126,7 @@ __git_ps1_show_upstream ()
|
|||||||
case "$key" in
|
case "$key" in
|
||||||
bash.showupstream)
|
bash.showupstream)
|
||||||
GIT_PS1_SHOWUPSTREAM="$value"
|
GIT_PS1_SHOWUPSTREAM="$value"
|
||||||
if [[ -z "${GIT_PS1_SHOWUPSTREAM}" ]]; then
|
if [ -z "${GIT_PS1_SHOWUPSTREAM}" ]; then
|
||||||
p=""
|
p=""
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
@ -187,14 +187,14 @@ __git_ps1_show_upstream ()
|
|||||||
upstream_type=${svn_upstream#/}
|
upstream_type=${svn_upstream#/}
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
elif [[ "svn+git" = "$upstream_type" ]]; then
|
elif [ "svn+git" = "$upstream_type" ]; then
|
||||||
upstream_type="@{upstream}"
|
upstream_type="@{upstream}"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
# Find how many commits we are ahead/behind our upstream
|
# Find how many commits we are ahead/behind our upstream
|
||||||
if [[ -z "$legacy" ]]; then
|
if [ -z "$legacy" ]; then
|
||||||
count="$(git rev-list --count --left-right \
|
count="$(git rev-list --count --left-right \
|
||||||
"$upstream_type"...HEAD 2>/dev/null)"
|
"$upstream_type"...HEAD 2>/dev/null)"
|
||||||
else
|
else
|
||||||
@ -206,8 +206,8 @@ __git_ps1_show_upstream ()
|
|||||||
for commit in $commits
|
for commit in $commits
|
||||||
do
|
do
|
||||||
case "$commit" in
|
case "$commit" in
|
||||||
"<"*) ((behind++)) ;;
|
"<"*) behind=$((behind+1)) ;;
|
||||||
*) ((ahead++)) ;;
|
*) ahead=$((ahead+1)) ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
count="$behind $ahead"
|
count="$behind $ahead"
|
||||||
@ -217,7 +217,7 @@ __git_ps1_show_upstream ()
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# calculate the result
|
# calculate the result
|
||||||
if [[ -z "$verbose" ]]; then
|
if [ -z "$verbose" ]; then
|
||||||
case "$count" in
|
case "$count" in
|
||||||
"") # no upstream
|
"") # no upstream
|
||||||
p="" ;;
|
p="" ;;
|
||||||
@ -243,7 +243,7 @@ __git_ps1_show_upstream ()
|
|||||||
*) # diverged from upstream
|
*) # diverged from upstream
|
||||||
upstream="|u+${count#* }-${count% *}" ;;
|
upstream="|u+${count#* }-${count% *}" ;;
|
||||||
esac
|
esac
|
||||||
if [[ -n "$count" && -n "$name" ]]; then
|
if [ -n "$count" ] && [ -n "$name" ]; then
|
||||||
__git_ps1_upstream_name=$(git rev-parse \
|
__git_ps1_upstream_name=$(git rev-parse \
|
||||||
--abbrev-ref "$upstream_type" 2>/dev/null)
|
--abbrev-ref "$upstream_type" 2>/dev/null)
|
||||||
if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
|
if [ $pcmode = yes ] && [ $ps1_expanded = yes ]; then
|
||||||
@ -265,7 +265,7 @@ __git_ps1_show_upstream ()
|
|||||||
# their own color.
|
# their own color.
|
||||||
__git_ps1_colorize_gitstring ()
|
__git_ps1_colorize_gitstring ()
|
||||||
{
|
{
|
||||||
if [[ -n ${ZSH_VERSION-} ]]; then
|
if [ -n "${ZSH_VERSION-}" ]; then
|
||||||
local c_red='%F{red}'
|
local c_red='%F{red}'
|
||||||
local c_green='%F{green}'
|
local c_green='%F{green}'
|
||||||
local c_lblue='%F{blue}'
|
local c_lblue='%F{blue}'
|
||||||
@ -417,7 +417,7 @@ __git_ps1 ()
|
|||||||
# incorrect.)
|
# incorrect.)
|
||||||
#
|
#
|
||||||
local ps1_expanded=yes
|
local ps1_expanded=yes
|
||||||
[ -z "${ZSH_VERSION-}" ] || [[ -o PROMPT_SUBST ]] || ps1_expanded=no
|
[ -z "${ZSH_VERSION-}" ] || eval '[[ -o PROMPT_SUBST ]]' || ps1_expanded=no
|
||||||
[ -z "${BASH_VERSION-}" ] || shopt -q promptvars || ps1_expanded=no
|
[ -z "${BASH_VERSION-}" ] || shopt -q promptvars || ps1_expanded=no
|
||||||
|
|
||||||
local repo_info rev_parse_exit_code
|
local repo_info rev_parse_exit_code
|
||||||
@ -502,11 +502,13 @@ __git_ps1 ()
|
|||||||
return $exit
|
return $exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $head == "ref: "* ]]; then
|
case $head in
|
||||||
|
"ref: "*)
|
||||||
head="${head#ref: }"
|
head="${head#ref: }"
|
||||||
else
|
;;
|
||||||
|
*)
|
||||||
head=""
|
head=""
|
||||||
fi
|
esac
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
head="$(git symbolic-ref HEAD 2>/dev/null)"
|
head="$(git symbolic-ref HEAD 2>/dev/null)"
|
||||||
@ -542,8 +544,8 @@ __git_ps1 ()
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local conflict="" # state indicator for unresolved conflicts
|
local conflict="" # state indicator for unresolved conflicts
|
||||||
if [[ "${GIT_PS1_SHOWCONFLICTSTATE-}" == "yes" ]] &&
|
if [ "${GIT_PS1_SHOWCONFLICTSTATE-}" = "yes" ] &&
|
||||||
[[ $(git ls-files --unmerged 2>/dev/null) ]]; then
|
[ "$(git ls-files --unmerged 2>/dev/null)" ]; then
|
||||||
conflict="|CONFLICT"
|
conflict="|CONFLICT"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user