dotfiles/home/bin/gstate

44 lines
866 B
Plaintext
Raw Normal View History

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