Skip to content

Instantly share code, notes, and snippets.

@DanielaValero
Last active July 20, 2016 12:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save DanielaValero/401edc324b0d168d791c to your computer and use it in GitHub Desktop.
Save DanielaValero/401edc324b0d168d791c to your computer and use it in GitHub Desktop.
git in prompt
#======= Config to see git branch in the prompt
#===== get current git branch name
function git_branch {
export gitbranch=[$(git rev-parse --abbrev-ref HEAD 2>/dev/null)]
if [ "$?" -ne 0 ]
then gitbranch=
fi
if [[ "${gitbranch}" == "[]" ]]
then gitbranch=
fi
}
#===== set usercolor based on whether we are running with Admin privs
function user_color {
id | grep "Admin" > /dev/null
RETVAL=$?
if [[ $RETVAL == 0 ]]; then
usercolor="[0;35m";
else
usercolor="[0;32m";
fi
}
# Set prompt
cwdcolor='[0;34m'
gitcolor='[1;31m'
user_color
# Show if there are unstaged (*) and/or staged (+) changes
export GIT_PS1_SHOWDIRTYSTATE=1
# Show if there is anything stashed ($)
export GIT_PS1_SHOWSTASHSTATE=1
# Show if there are untracked files (%)
export GIT_PS1_SHOWUNTRACKEDFILES=1
# Show how we're tracking relative to upstream
#export GIT_PS1_SHOWUPSTREAM="verbose"
export GIT_PAGER='less -+$LESS -RS'
source /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-completion.bash
source /Applications/Xcode.app/Contents/Developer/usr/share/git-core/git-prompt.sh
GIT_PS1_SHOWDIRTYSTATE=true
export PS1='\[\e${usercolor}\]\u:\[\e${cwdcolor}\]\w/\[\e${gitcolor}\]$(__git_ps1 "(%s)")\[\033[00m\]$ '
# Get git in the prompt config
if [ -f ~/.bash_gitprompt ]; then
. ~/.bash_gitprompt
fi
# ========= Aliases
alias tree="ls -R | grep ":" | sed -e 's/://' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/'"
alias removeMerged="git branch --merged | grep -v \"\*\" | xargs -n 1 git branch -d"
alias forceRemove="git branch --no-merged | grep -v \"\*\" | xargs -n 1 git branch -D"
alias apache="apachectl"
alias myIp="ifconfig | grep inet"
alias ignoreFolder="git ls-files -z | xargs -0 git update-index --assume-unchanged"
#alias lastdate=$(git show -s --format=%ad `git rev-list--tags --max-count=1`)
#alias myChangelog = "git log --pretty=format:'-(%an): %s%n%b' --since='$lastdate' | grep -v 'merge'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment