Skip to content

Instantly share code, notes, and snippets.

@johnh
Last active November 4, 2015 06:13
Show Gist options
  • Save johnh/d0ebd6a9f12bcc86aed3 to your computer and use it in GitHub Desktop.
Save johnh/d0ebd6a9f12bcc86aed3 to your computer and use it in GitHub Desktop.
Fixed the f@#$% wrapping prompt after all these years...
export COLOR_NC='\033[0m' # No Color
export COLOR_WHITE='\033[1;37m'
export COLOR_BLACK='\033[0;30m'
export COLOR_BLUE='\033[0;34m'
export COLOR_LIGHT_BLUE='\033[1;34m'
export COLOR_GREEN='\033[0;32m'
export COLOR_LIGHT_GREEN='\033[1;32m'
export COLOR_CYAN='\033[0;36m'
export COLOR_LIGHT_CYAN='\033[1;36m'
export COLOR_RED='\033[0;31m'
export COLOR_LIGHT_RED='\033[1;31m'
export COLOR_PURPLE='\033[0;35m'
export COLOR_LIGHT_PURPLE='\033[1;35m'
export COLOR_BROWN='\033[0;33m'
export COLOR_YELLOW='\033[1;33m'
export COLOR_GRAY='\033[1;30m'
export COLOR_LIGHT_GRAY='\033[0;37m'
#====================================================================================
# FUNCTION
#====================================================================================
parse_git_branch() {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/[\1]/'
}
#====================================================================================
# PROMPT
#====================================================================================
PROMPT_COMMAND='DIR=`pwd|sed -e "s!$HOME!~!"`; if [ ${#DIR} -gt 30 ]; then CurDir=${DIR:0:12}...${DIR:${#DIR}-15}; else CurDir=$DIR; fi'
#before
#export PS1="\n\033[0;35m[\h]\033[0;36m[\$CurDir]\033[0;32m\$(parse_git_branch)\033[0m \$ "
#after... the secret is enclosing non-printable character sequenes in \[ and \]
export PS1="\n\[${COLOR_GREEN}\][\h]\[${COLOR_LIGHT_BLUE}\][\$CurDir]\[${COLOR_PURPLE}\]\$(parse_git_branch)\[${COLOR_NC}\]\$ "
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment