Last active
August 29, 2015 14:10
-
-
Save emning/37ef2ff6a9c17a85669c to your computer and use it in GitHub Desktop.
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
#!/bin/bash | |
# | |
# A readable, non-ugly, fast and flexible bash prompt | |
# | |
# features: | |
# - current git branch | |
# - current python virtualenv | |
# - current chroot | |
# - show return code if != 0 | |
# | |
# 2014-11-24 - Runar Balstad Jensen <runar@emning.no> | |
# colors | |
RED='\[\e[1;31m\]' | |
GRN='\[\e[1;32m\]' | |
YEL='\[\e[1;33m\]' | |
BLU='\[\e[1;34m\]' | |
PUR='\[\e[1;35m\]' | |
CYN='\[\e[1;36m\]' | |
WHT='\[\e[1;37m\]' | |
RST='\[\e[0m\]' | |
[[ -x /usr/bin/git ]] && HAS_GIT=1 || HAS_GIT=0 | |
function colorprompt() { | |
RET=$? | |
PS1="" | |
# virtualenv and chroot | |
PS1+="${VIRTUAL_ENV:+$PUR[$(basename $VIRTUAL_ENV)]$RST }" | |
PS1+="${debian_chroot:+($debian_chroot) }" | |
# green@yellow for user, red@purple for root | |
(( EUID )) && PS1+="$GRN\u@$YEL" || PS1+="$RED\u@$PUR" | |
# hostname | |
PS1+="\h " | |
# git branch | |
if (( HAS_GIT )) | |
then | |
# this is a lot quicker than __git_ps1 | |
BRANCH="$(git rev-parse --symbolic-full-name --abbrev-ref HEAD 2> /dev/null)" | |
[[ -n "$BRANCH" ]] && PS1+="$CYN$BRANCH " | |
fi | |
# path | |
PS1+="$BLU\w " | |
# show return code if != 0 | |
(( RET )) && PS1+="$RED$RET$BLU " | |
# hash or dollar | |
(( EUID )) && PS1+='$' || PS1+='#' | |
PS1+="$RST " | |
# xterm title | |
case "$TERM" in | |
xterm*|rxvt*) | |
PS1+="\[\e]0;${VIRTUAL_ENV:+[$(basename $VIRTUAL_ENV)] }${debian_chroot:+($debian_chroot) }\u@\h: \w\a\]" | |
;; | |
*) | |
;; | |
esac | |
} | |
PROMPT_COMMAND="colorprompt; history -a" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment