Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
100 lines (86 sloc) 2.64 KB
##==============================================================================
## Generate a cool prompt
## Requires vcprompt from https://bitbucket.org/mitsuhiko/vcprompt/
##==============================================================================
if [ `id -u` == '0' ]; then
NICEPROMPT_USER_COLOR="[1;31m"
else
NICEPROMPT_USER_COLOR="[1;37m"
fi
NICEPROMPT_HOST_COLOR="[1;36m"
NICEPROMPT_PWD_COLOR="[0;32m"
niceprompt_vcprompt() {
_vc_prompt=$' \033[0;37m<\033[1;34m%n\033[00m:\033[1;37m%[unknown]b\033[1;32m%m\033[1;31m%u\033[0;37m>\033[0m'
if which vcprompt &>/dev/null; then
vcprompt -f "${_vc_prompt}"
fi
}
niceprompt_lastcommandfailed() {
code=$?
if [ "${code}" != 0 ]; then
echo $'\033[37m>>> exited \033[31m'"${code}"$'\033[0m\n.\b'
fi
}
niceprompt_backgroundjobs() {
jobs | python -c 'if 1:
import sys
items = ["\033[36m%s\033[37m" % x.split()[2]
for x in sys.stdin.read().splitlines()]
if items:
if len(items) > 2:
string = "%s, and %s" % (", ".join(items[:-1]), items[-1])
else:
string = ", ".join(items)
print("\033[37m (running %s)" % string)
'
}
niceprompt_virtualenv() {
if [ -n "${VIRTUAL_ENV}" ]; then
ENV_NAME=$( basename "${VIRTUAL_ENV}" )
echo -n $' \033[0;35mvenv:\033[1;35m'"${ENV_NAME}"$'\033[00m'
fi
}
niceprompt_ssh() {
if [ -n "${SSH_CONNECTION}" ]; then
echo -n $' \033[0;36mssh\033[0m'
fi
}
niceprompt_screen() {
if [ "$TERM" == "screen" ]; then
#echo -n $' \033[0;37mscreen:'"$STY"$'\033[0m'
echo -n $' \033[0;33mscreen\033[0m'
fi
}
niceprompt_chroot() {
if [ -n "$debian_chroot" ]; then
echo -ne " \e[0;37mchroot:\e[0m${debian_chroot}"
fi
if [ -n "$SCHROOT_SESSION_ID" ]; then
echo -ne " \e[0;37mschroot:\e[0m${SCHROOT_SESSION_ID}"
fi
}
export NICEPROMPT_BASEPROMPT='\n\
` niceprompt_lastcommandfailed `\
\033[0;37m[ \033'"$NICEPROMPT_USER_COLOR"'\u\
\033'"$NICEPROMPT_HOST_COLOR"'@\h\033[0;37m ] \033[0m\
\033[1;33m\w\033[0m\
` niceprompt_vcprompt `\
` niceprompt_backgroundjobs `\
` niceprompt_chroot `\
` niceprompt_virtualenv `\
` niceprompt_ssh `\
` niceprompt_screen `\
\033[0m'
export PS1="\033[G${NICEPROMPT_BASEPROMPT}
\[\033[1;32m\]\\\$\[\033[0m\] "
## Don't let virtualenv show prompts by itself
VIRTUAL_ENV_DISABLE_PROMPT=1
## Let's change the PROMPT_COMMAND too, to make it more useful..
case "$TERM" in
xterm*|rxvt*)
## by the way, we might want to use this instead of PS1 stuff..
PROMPT_COMMAND='echo -ne "\033]0;${HOSTNAME%%.*} (${USER}) ${PWD}\007"'
;;
*)
;;
esac