Skip to content

Instantly share code, notes, and snippets.

@igal
Created May 10, 2009 06:19
Show Gist options
  • Save igal/109520 to your computer and use it in GitHub Desktop.
Save igal/109520 to your computer and use it in GitHub Desktop.
My bash prompts: short, long, and git status
# My bash prompts. To use, source the code below and call the name of the function, e.g. "shortprompt".
# Display smiley indicator for return values, date, and truncated path, e.g.:
### igal@avijja:z #13 12:37 :)
shortprompt() {
export PS1="\u@\h:\W #\! \A \`if [ \$? == 0 ]; then echo \:\); else echo \:\(; fi\` "
}
# Display shortprompt, but with non-truncated path, e.g.:
### igal@murad:~/mtmp/rubyfix #17 23:40 :)
longprompt() {
export PS1="\u@\h:\w #\! \A \`if [ \$? == 0 ]; then echo \:\); else echo \:\(; fi\` "
}
# Display git branch information, e.g.:
### openconferenceware::master :)
gitprompt() {
# Extract git branch information
function parse_git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo ${ref#refs/heads/}
}
# Define shell prompt
export PS1="\W::\`parse_git_branch\` \`if [ \$? == 0 ]; then echo \:\); else echo \:\(; fi\` "
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment