Fix inconsistencies

Some variables were delimited by curly braces, others weren't. Enclose
all multi-character variable names in curly braces.

Some variables were redundant. Remove them.
This commit is contained in:
xylous 2022-02-04 22:42:44 +02:00
parent 7f06c8c7b5
commit 21001cab5f
No known key found for this signature in database
GPG Key ID: A9E6DA43F5E78D24

View File

@ -23,36 +23,36 @@ function gitstatus()
unset STATUS unset STATUS
git_grab_current_branch git_grab_current_branch
local branch="$REPLY" local branch="${REPLY}"
git_grab_remote_branch git_grab_remote_branch
local remote="$REPLY" local remote="${REPLY}"
[[ ! -z "$remote" ]] \ [[ ! -z "$remote" ]] \
&& git_local_remote_diffs "$branch" "$remote" \ && git_local_remote_diffs "$branch" "$remote" \
&& local commit_diffs="$REPLY" && local commit_diffs="$REPLY"
git_determine_color $modified $staged $deleted $untracked git_determine_color ${modified} ${staged} ${deleted} ${untracked}
local color="$REPLY" local color="${REPLY}"
(( modified > 0 )) \ (( modified > 0 )) \
&& modified="!$modified " && modified="!${modified} "
(( staged > 0 )) \ (( staged > 0 )) \
&& staged="+$staged " && staged="+${staged} "
(( deleted > 0 )) \ (( deleted > 0 )) \
&& deleted="-$deleted " && deleted="-${deleted} "
(( untracked > 0 )) \ (( untracked > 0 )) \
&& untracked="?$untracked " && untracked="?${untracked} "
local output="$color" local output="$color"
output+="$branch " output+="${branch} "
output+="$commit_diffs" output+="${commit_diffs}"
output+="$modified" output+="${modified}"
output+="$staged" output+="${staged}"
output+="$deleted" output+="${deleted}"
output+="$untracked" output+="${untracked}"
local true_output="$(sed 's/[ \t]*$//' <<<"$output")" # remove trailing whitespace local true_output="$(sed 's/[ \t]*$//' <<<"${output}")" # remove trailing whitespace
if [[ "$1" == "-i" ]]; then if [[ "$1" == "-i" ]]; then
true_output+=" " true_output+=" "
@ -90,7 +90,7 @@ function git_grab_current_branch()
function git_grab_remote_branch() function git_grab_remote_branch()
{ {
local symbolic_ref="$(git symbolic-ref -q HEAD)" local symbolic_ref="$(git symbolic-ref -q HEAD)"
typeset -g REPLY="$(git for-each-ref --format='%(upstream:short)' "$symbolic_ref")" typeset -g REPLY="$(git for-each-ref --format='%(upstream:short)' "${symbolic_ref}")"
} }
### ###
@ -120,7 +120,7 @@ function parse_git_status()
esac esac
done done
typeset -g STATUS=("$modified" "$staged" "$deleted" "$untracked") typeset -g STATUS=("${modified}" "${staged}" "${deleted}" "${untracked}")
return 0 return 0
} }
@ -134,17 +134,17 @@ function git_local_remote_diffs()
local local_branch="$1" local local_branch="$1"
local remote_branch="$2" local remote_branch="$2"
local differences="$(git rev-list --left-right --count $local_branch...$remote_branch)" local differences="$(git rev-list --left-right --count ${local_branch}...${remote_branch})"
local commits_ahead=$(echo -n "$differences" | awk '{print $1}') local commits_ahead=$(echo -n "${differences}" | awk '{print $1}')
local commits_behind=$(echo -n "$differences" | awk '{print $2}') local commits_behind=$(echo -n "${differences}" | awk '{print $2}')
local ahead="" behind="" local ahead="" behind=""
local result="" local result=""
(( $commits_ahead > 0 )) \ (( $commits_ahead > 0 )) \
&& ahead="$commits_ahead" && ahead="${commits_ahead}"
(( $commits_behind > 0 )) \ (( $commits_behind > 0 )) \
&& behind="$commits_behind" && behind="${commits_behind}"
if [[ ! -z "${ahead}" ]]; then if [[ ! -z "${ahead}" ]]; then
result="${ahead} " result="${ahead} "
@ -164,14 +164,12 @@ function git_local_remote_diffs()
### ###
function git_determine_color() function git_determine_color()
{ {
local green=$'%F{yellow}'
local yellow=$'%F{green}'
for i in "$@"; do for i in "$@"; do
if (( $i > 0 )); then if (( $i > 0 )); then
typeset -g REPLY="$green" typeset -g REPLY=$'${yellow}'
return 0 return 0
fi fi
done done
typeset -g REPLY="$yellow" typeset -g REPLY=$'${green}'
return 0 return 0
} }