Skip to content

Instantly share code, notes, and snippets.

@RoLYroLLs
Last active August 29, 2015 14:00
Show Gist options
  • Save RoLYroLLs/11196798 to your computer and use it in GitHub Desktop.
Save RoLYroLLs/11196798 to your computer and use it in GitHub Desktop.
Git Aware Bash Prompt with some shell shortcuts to Git plumbing
# Git shortcuts
alias gb='git branch'
alias gs='git status'
alias gsu='git status -su'
alias ga='git add'
alias gaa='git add -A'
alias gun='git reset HEAD'
alias gc='git commit'
alias gcm='git commit -m'
alias gco='git checkout'
alias gl='git log'
alias glol='git lol'
alias glola='git lola'
# Allow bash to be git aware
. ~/.bash_prompt_git_aware
# Base taken from https://gist.github.com/yujily/1144329
#
# Kept the default bash prompt, spaces and all, unless you were in a git repo
#
# Prompt if NOT IN Git repo: {computername}:{current directory} {username}$
#
# Prompt if IN Git repo: {computername}:{current directory} {username} ({branch name with color})$
#
# Git status bash prompt
#
# In addition to printing the current working directory, this prompt will
# show a number of things if you are in a git repository:
# - The current branch you are in
# - Whether there are untracked files in the repository (there will be an
# asterisk after the branch nome if there are)
# - Whether there are any unmerged/unstaged/staged changes or if the directory
# is clean. See below for the colors that will be used, and change them if
# you'd like.
# Storing these color codes for later use
# Just Color
clrbase='\[\033'
clrblk='30m' # Black
clrred='31m' # Red
clrgrn='32m' # Green
clrylw='33m' # Yellow
clrblu='34m' # Blue
clrpur='35m' # Purple
clrcyn='36m' # Cyan
clrwht='37m' # White
# Regular
txtblk='0;30m' # Black
txtred='0;31m' # Red
txtgrn='0;32m' # Green
txtylw='0;33m' # Yellow
txtblu='0;34m' # Blue
txtpur='0;35m' # Purple
txtcyn='0;36m' # Cyan
txtwht='0;37m' # White
# Bold
bldblk='1;30m' # Black
bldred='1;31m' # Red
bldgrn='1;32m' # Green
bldylw='1;33m' # Yellow
bldblu='1;34m' # Blue
bldpur='1;35m' # Purple
bldcyn='1;36m' # Cyan
bldwht='1;37m' # White
# Underline
undblk='4;30m' # Black
undred='4;31m' # Red
undgrn='4;32m' # Green
undylw='4;33m' # Yellow
undblu='4;34m' # Blue
undpur='4;35m' # Purple
undcyn='4;36m' # Cyan
undwht='4;37m' # White
# Background
bakblk='40m' # Black
bakred='41m' # Red
bakgrn='42m' # Green
bakylw='43m' # Yellow
bakblu='44m' # Blue
bakpur='45m' # Purple
bakcyn='46m' # Cyan
bakwht='47m' # White
txtrst='0m' # Text Reset
# Set color for the directory listing in the prompt
dir_listing_color=$clrgrn
# Set colors for different repository states
unmerged_color=$clrpur
unstaged_color=$clrred
staged_color=$clrylw
clean_color=$clrgrn
function git_color {
git_status=`git status 2> /dev/null`
if [ -n "`echo $git_status | grep "Unmerged paths:"`" ]; then
echo -e $unmerged_color
elif [ -n "`echo $git_status | grep "Changes not staged for commit:"`" ]; then
echo -e $unstaged_color
elif [ -n "`echo $git_status | grep "Changes to be committed:"`" ]; then
echo -e $staged_color
else
echo -e $clean_color
fi
}
function git_branch {
git_branch=`git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
if [ -n "`git status 2> /dev/null | grep "Untracked files:"`" ]; then
untracked="*"
fi
if [ "`expr "$git_branch" : '.*'`" -gt "0" ]; then
echo $git_branch$untracked
fi
}
PS1='$( RET=`git_branch`; if [ -n "$RET" ] ; then echo "\[\033[1;$clrcyn\]\W \[\033[1;`git_color`\]($RET)\[\033[0m\]\n\n"; else echo "\[\033[32m\]\h:\W \[\033[33m\]\u\[\033[0m\]"; fi )\$ '
#PS1='\[\033]0;$MSYSTEM:${PWD//[^[:ascii:]]/?}\007\]\n\[\033[32m\]\u@\h \[\033[33m\]\w$(__git_ps1)\[\033[0m\]\n$ ' #pc bash default
#PS1='\h:\W \u\$ ' #mac terminal default
PS2="> "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment