Created
October 26, 2016 03:24
-
-
Save amcooper/ee10617c34ec4829869ae21cdd1d67fd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# just add to the .profile or .bash_rc | |
# don't set prompt if this is not interactive shell | |
[[ $- != *i* ]] && return | |
color_default='\['`tput sgr0`'\]' | |
color_red='\['`tput sgr0; tput setaf 1`'\]' | |
color_green='\['`tput sgr0; tput setaf 2`'\]' | |
color_yellow='\['`tput sgr0; tput setaf 3`'\]' | |
color_light_blue='\['`tput sgr0; tput setaf 4`'\]' | |
# make git-repositories have the branch and its status displayed in the bash prompt | |
parse_git_branch () | |
{ | |
if git rev-parse --git-dir >/dev/null 2>&1 | |
then | |
gitver=$(git branch 2>/dev/null| sed -n '/^\*/s/^\* //p') | |
if git diff --quiet 2>/dev/null >&2 | |
then | |
gitver="- ${color_green}[${gitver}]${color_default} " | |
else | |
gitver="- ${color_red}[${gitver}]${color_default} " | |
fi | |
stashcount=$(git stash list|wc -l) | |
if [ $stashcount -gt 0 ] | |
then | |
gitver="${gitver} ${color_red}[${stashcount//[[:space:]]} stashed]${color_default}" | |
fi | |
else | |
gitver="" | |
return 0 | |
fi | |
} | |
prompt_command_function () | |
{ | |
parse_git_branch | |
# [Not sure wut this means --> ] Commented out so that .bash_profile's git prompt can have precedence | |
# From: http://www.ibiblio.org/pub/Linux/docs/HOWTO/other-formats/html/Xterm-Title-html.tar.gz | |
case $TERM in | |
xterm*) | |
export PS1="\[\033]0;\w\007\]\n${color_yellow}#\# - \t - \w ${gitver}${color_default}\n${color_light_blue}->${color_default} " | |
;; | |
*) | |
export PS1="\n${color_yellow}#\# - \t - \w ${gitver}${color_default}\n${color_light_blue}->${color_default} " | |
;; | |
esac | |
# If the ibiblio thing above blows up, the below works fine. | |
# export PS1="\n${color_yellow}#\# - \t - \w ${gitver}${color_default}\n${color_light_blue}->${color_default} " | |
} | |
export PROMPT_COMMAND=prompt_command_function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment