Skip to content

Instantly share code, notes, and snippets.

@nickbauman
Last active May 15, 2016 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickbauman/ccd6dc754a0e7efd35e13c2f58744295 to your computer and use it in GitHub Desktop.
Save nickbauman/ccd6dc754a0e7efd35e13c2f58744295 to your computer and use it in GitHub Desktop.
A star-gazing colleague shared this with me. I find it useful for taming some of the many git rough edges.
# For the ~/.gitconfig file:
[alias]
st = status
co = checkout
ci = commit
cp = cherry-pick
br = branch
undo = reset HEAD~1 --mixed
back = stash pop
stop = stop-tracking
lol = log --graph --oneline --decorate --all
hist = log --oneline --graph --decorate
s = status -s
wip = !git add -u && git commit -m "WIP"
-----------------------------------------------------
# For ~/.profile:
source ~/scripts/git-completion.bash
# To change the prompt to show current folder:[current-branch *optional-status-of-branch*]>
find_git_prompt() {
GIT_PROMPT=""
GIT_REPO_PATH=`git rev-parse --git-dir 2>/dev/null`
if [[ $GIT_REPO_PATH != '' && $GIT_REPO_PATH != '~' && $GIT_REPO_PATH != "$HOME/.git" ]]; then
GIT_BRANCH=`git symbolic-ref -q HEAD | sed 's/refs\/heads\///' | cut -d "-" -f 1-2`
GIT_MODE=""
if [[ -e "$GIT_REPO_PATH/BISECT_LOG" ]]; then
GIT_MODE=" +bisect"
elif [[ -e "$GIT_REPO_PATH/MERGE_HEAD" ]]; then
GIT_MODE=" +merge"
elif [[ -e "$GIT_REPO_PATH/rebase" || -e "$GIT_REPO_PATH/rebase-apply" || -e "$GIT_REPO_PATH/rebase-merge" || -e "$GIT_REPO_PATH/../.dotest" ]]; then
GIT_MODE=" +rebase"
fi
GIT_DIRTY=""
if [[ "$GIT_REPO_PATH" != '.' && `git ls-files -m` != "" ]]; then
GIT_DIRTY=" ✗"
fi
GIT_PROMPT="[$GIT_BRANCH$GIT_MODE$GIT_DIRTY]"
fi
echo $GIT_PROMPT
}
# Borrowed from https://github.com/jimeh/git-aware-prompt/blob/master/colors.sh
# Modified by @jaw6
# Regular
txtblk="$(tput setaf 0 2>/dev/null || echo '\e[0;30m')" # Black
txtred="$(tput setaf 1 2>/dev/null || echo '\e[0;31m')" # Red
txtgrn="$(tput setaf 2 2>/dev/null || echo '\e[0;32m')" # Green
txtylw="$(tput setaf 3 2>/dev/null || echo '\e[0;33m')" # Yellow
txtblu="$(tput setaf 4 2>/dev/null || echo '\e[0;34m')" # Blue
txtpur="$(tput setaf 5 2>/dev/null || echo '\e[0;35m')" # Purple
txtcyn="$(tput setaf 6 2>/dev/null || echo '\e[0;36m')" # Cyan
txtwht="$(tput setaf 7 2>/dev/null || echo '\e[0;37m')" # White
# Bold
bldblk="$(tput setaf 0 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;30m')" # Black
bldred="$(tput setaf 1 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;31m')" # Red
bldgrn="$(tput setaf 2 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;32m')" # Green
bldylw="$(tput setaf 3 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;33m')" # Yellow
bldblu="$(tput setaf 4 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;34m')" # Blue
bldpur="$(tput setaf 5 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;35m')" # Purple
bldcyn="$(tput setaf 6 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;36m')" # Cyan
bldwht="$(tput setaf 7 2>/dev/null)$(tput bold 2>/dev/null || echo '\e[1;37m')" # White
# Underline
undblk="$(tput setaf 0 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;30m')" # Black
undred="$(tput setaf 1 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;31m')" # Red
undgrn="$(tput setaf 2 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;32m')" # Green
undylw="$(tput setaf 3 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;33m')" # Yellow
undblu="$(tput setaf 4 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;34m')" # Blue
undpur="$(tput setaf 5 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;35m')" # Purple
undcyn="$(tput setaf 6 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;36m')" # Cyan
undwht="$(tput setaf 7 2>/dev/null)$(tput smul 2>/dev/null || echo '\e[4;37m')" # White
# Background
bakblk="$(tput setab 0 2>/dev/null || echo '\e[40m')" # Black
bakred="$(tput setab 1 2>/dev/null || echo '\e[41m')" # Red
bakgrn="$(tput setab 2 2>/dev/null || echo '\e[42m')" # Green
bakylw="$(tput setab 3 2>/dev/null || echo '\e[43m')" # Yellow
bakblu="$(tput setab 4 2>/dev/null || echo '\e[44m')" # Blue
bakpur="$(tput setab 5 2>/dev/null || echo '\e[45m')" # Purple
bakcyn="$(tput setab 6 2>/dev/null || echo '\e[46m')" # Cyan
bakwht="$(tput setab 7 2>/dev/null || echo '\e[47m')" # White
# Reset
txtrst="$(tput sgr 0 2>/dev/null || echo '\e[0m')" # Text Reset
# Now set the prompt:
export PS1="\n\[$(tput bold)$txtblk\]\w:\[$txtrst$txtblu\]\$(find_git_prompt)\[${bldblk}\]➤\[${txtrst}\] "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment