dotfiles/home/bin/gstate

44 lines
842 B
Plaintext
Raw Permalink Normal View History

2021-02-11 16:25:39 +00:00
#!/bin/bash
heading() {
# or "\e" on *nix
HEAD="\033[96m\033[1m"
DONE="\033[0m"
echo -e "${HEAD}${1}${DONE}"
}
# 0) find local git repo, or fail now
GIT_ROOT=$(git rev-parse --show-toplevel 2>/dev/null)
if [[ "$GIT_ROOT" == "" ]]; then
echo "! can't find nearby git repository" >&2
exit 1
fi
# 1) show git branches
heading Branches
git branch --color -v
echo
# 2) file status
heading Status
git status
echo
# 3) stashed changes
if [[ -n $(git stash list) ]]; then
heading Stash
git stash list | sed "s/^/ /"
echo
fi
# 4) divergence from source
UPSTREAM=$(git rev-parse --abbrev-ref --symbolic-full-name @{u} 2>/dev/null)
if [[ -n "${UPSTREAM}" ]]; then
heading "upstream [${UPSTREAM}] divergence"
git diff -r $UPSTREAM --name-only --color | sed "s/^/ /"
else
heading "WARNING- no upstream configured"
fi
echo