Fix branch name spacing

On branches tracking remotes, there would be two spaces between the last
character and the first character in the status part. On other branches,
there'd only be one. Make it so that there's only one space at all
times.

In the function calculating differences between local and remote
histories, an extra space was added before the first part, thus where
the second space came from. Remove that.
This commit is contained in:
xylous 2021-09-15 20:25:31 +03:00
parent fb3045131b
commit 8029f58990

View File

@ -29,7 +29,7 @@ function gitstatus()
(( deleted > 0 )) \
&& deleted="-$deleted "
(( untracked > 0 )) \
&& untracked="?$untracked"
&& untracked="?$untracked "
local output="$color"
output+="$branch "
@ -38,9 +38,10 @@ function gitstatus()
output+="$staged"
output+="$deleted"
output+="$untracked"
output+=$'%F{default}'
sed 's/[ ]+$//' <<<"$output" # remove trailing whitespace
local true_output="$(sed 's/[ \t]*$//' <<<"$output")" # remove trailing whitespace
true_output+=$'%F{default}'
echo "${true_output}"
unset REPLY
}
@ -71,7 +72,7 @@ function git_grab_current_branch()
function git_grab_remote_branch()
{
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")"
}
###
@ -121,12 +122,15 @@ function git_local_remote_diffs()
local ahead="" behind=""
(( $commits_ahead > 0 )) \
&& ahead=" $commits_ahead"
&& ahead="$commits_ahead"
(( $commits_behind > 0 )) \
&& behind=" $commits_behind "
&& behind="$commits_behind"
typeset -g REPLY="$ahead $behind"
return 0
if [[ ! -z "${ahead}" ]] || [[ ! -z "${behind}" ]]; then
typeset -g REPLY="$ahead $behind"
return 0
fi
return 1
}
###