Skip to content

Instantly share code, notes, and snippets.

@ritcheyer
Last active August 29, 2015 13:57
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 ritcheyer/9646057 to your computer and use it in GitHub Desktop.
Save ritcheyer/9646057 to your computer and use it in GitHub Desktop.
bash script to output whether I have changes on my branch folder or not
# Time Variables
Time12h="\T"
Time12a="\@"
# where am i?
print_before_the_prompt () {
# is this a git or hg branch?
DVCS=''
IS_GIT_BRANCH=`git branch 2> /dev/null | grep \* | awk '{print $2}'`
IS_HG_BRANCH=`hg prompt "{{branch}}{ at {bookmark}}{status} " 2> /dev/null`
if [[ "$IS_GIT_BRANCH" != "" ]]; then
BRANCH_NONE=`git status | grep "nothing" > /dev/null 2>&1`
BRANCH_ADDS=`git status | grep "untracked" > /dev/null 2>&1`
BRANCH_MODS=`git status | grep "changes" > /dev/null 2>&1`
if [[ "$BRANCH_NONE" != "" ]]; then
BRANCH_STATUS=""
elif [[ "$BRANCH_MODS" != "" ]]; then
BRANCH_STATUS="w/modifications"
elif [ "$BRANCH_ADDS" != "" ] && [ "$BRANCH_MODS" == "" ]; then
BRANCH_STATUS="w/additions"
fi
DVCS="git → $IS_GIT_BRANCH $BRANCH_STATUS"
elif [[ "$IS_HG_BRANCH" != "" ]]; then
DVCS="hg → $IS_HG_BRANCH"
else
DVCS=""
fi
printf "\n$txtpur%s $txtcyn%s $txtylw%s $txtred%s \n$txtrst" "💩 " "$PWD/" " $DVCS"
}
PROMPT_COMMAND=print_before_the_prompt
export PS1=$txtblu$Time12a$txtrst' → '
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment