Skip to content

Instantly share code, notes, and snippets.

@samthor

samthor/gstate

Last active Jun 17, 2019
Embed
What would you like to do?
Sam's git status replacement
#!/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
@AJPoulter-Soton

This comment has been minimized.

Copy link

@AJPoulter-Soton AJPoulter-Soton commented Jun 11, 2019

Nice little script. I like it!

@jimmo

This comment has been minimized.

Copy link

@jimmo jimmo commented Jun 17, 2019

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
You can’t perform that action at this time.