Created
December 3, 2011 03:39
-
-
Save ssimeonov/1425931 to your computer and use it in GitHub Desktop.
Cool bash color prompt for Git fans
This file contains 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
# git will show dirty branches | |
GIT_PS1_SHOWDIRTYSTATE=true | |
# Directory shortening for prompt | |
# Edit this based on the directory structures you like to use | |
function shorten_dir() { | |
d=$(pwd) | |
d=${d/\/Users\/sim\/dev\/spx/SPX} | |
d=${d/\/Users\/sim\/dev\/rails_projects/RP} | |
d=${d/\/Users\/sim\/dev\/proj/PROJ} | |
d=${d/\/Users\/sim\/dev/DEV} | |
d=${d/\/Users\/sim/\~} | |
echo $d | |
} | |
# Magic color prompt authored by the genetic clone of a psychedelic cross between Brian Fox and Linus Torvalds | |
# Example: 1996[SPX/spx-web(dev *)]$ | |
# 1996: command number in history | |
# SPX: shorthand for ~/dev/spx; see shorten_dir above | |
# SPX/spx-web: pwd | |
# dev: current Git branch | |
# *: branch is dirty | |
# $: color is based on the exit code of last command: OK (green) or not (red) | |
export PROMPT_COMMAND='PS1="\[\033[0;33m\]\!\[\033[0;32m\][$(shorten_dir)\[\033[35m\]$(__git_ps1 "(%s)")\[\033[32m\]]\`if [[ \$? = "0" ]]; then echo "\\[\\033[32m\\]"; else echo "\\[\\033[31m\\]"; fi\`\$\[\033[0m\] ";' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment