Improved display for 'dots status', with info about remote and local commits
This commit is contained in:
parent
6a4a1e87a6
commit
de19a757b9
1 changed files with 31 additions and 11 deletions
|
@ -69,20 +69,40 @@ status() {
|
||||||
local -a packages
|
local -a packages
|
||||||
packages=($argv)
|
packages=($argv)
|
||||||
(( $#packages == 0 )) && packages=( $DOTFILES/*(N:t) )
|
(( $#packages == 0 )) && packages=( $DOTFILES/*(N:t) )
|
||||||
local length=${#${(O@)packages//?/X}[1]} git_status
|
local length=${#${(O@)packages//?/X}[1]} git_status remote_status
|
||||||
cd $DOTFILES
|
|
||||||
for p in $packages; do
|
for p in $packages; do
|
||||||
pushd $p
|
cd $DOTFILES/$p
|
||||||
printf "%${length}s " $p
|
# Always show the repo's name at the beginning of the line.
|
||||||
git_status="$(command git status --porcelain --ignore-submodules -unormal 2>/dev/null)"
|
printf %${length}s' ' $p
|
||||||
|
|
||||||
|
# Check if the package is actually a repo. It might not be if it's brand-new.
|
||||||
|
git_status="$(git status --porcelain --ignore-submodules -unormal 2>/dev/null)"
|
||||||
if (( $? != 0 )); then
|
if (( $? != 0 )); then
|
||||||
print -P "%F{247}not a git repository%f"
|
printf '%9s' '' # space across to the last column
|
||||||
elif [[ -z $git_status ]]; then
|
print -P %F{247}not a git repository%f
|
||||||
print -P "%F{green}clean%f"
|
continue
|
||||||
else
|
fi
|
||||||
print -P "%F{red}unclean%f"
|
|
||||||
|
# Indicate the working tree status.
|
||||||
|
if [[ -z $git_status ]]; then
|
||||||
|
print -Pn %F{green}clean%f' '
|
||||||
|
else
|
||||||
|
print -Pn %F{red}unclean%f
|
||||||
|
fi
|
||||||
|
printf '%2s' ''
|
||||||
|
|
||||||
|
# If the repository has an upstream remote configured, indicate the number
|
||||||
|
# of commits out of sync we are from the remote.
|
||||||
|
if git rev-parse --abbrev-ref @{u} &>/dev/null; then
|
||||||
|
remote_status="$(git rev-list --left-right --count HEAD...@{u} 2>/dev/null)"
|
||||||
|
remote_status=(${(ps:\t:)remote_status})
|
||||||
|
print -Pn %F{cyan}
|
||||||
|
(( $remote_status[1] > 0 )) && print -n $remote_status[1]⇡
|
||||||
|
(( $remote_status[2] > 0 )) && print -n $remote_status[2]⇣
|
||||||
|
print -P %f
|
||||||
|
else
|
||||||
|
print -P %F{247}no remote%f
|
||||||
fi
|
fi
|
||||||
popd
|
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue