Last active
June 17, 2019 01:57
-
-
Save samthor/c333e87f70631ecee50cd46f00e175cd to your computer and use it in GitHub Desktop.
Sam's git status replacement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
If you name this file git-state
and put it in your $PATH
then it will automatically be available as git state
(for consistency with other git commands). Also then you can alias to something short it in your ~/.gitconfig
[alias]
st = state
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice little script. I like it!