Skip to content

Instantly share code, notes, and snippets.

@bemeyert
Last active August 29, 2015 13:56
Show Gist options
  • Save bemeyert/9205602 to your computer and use it in GitHub Desktop.
Save bemeyert/9205602 to your computer and use it in GitHub Desktop.
Another tunable Subversion Bash prompt. Insert into or source in your .bashrc.
# Define some colors first.
# CAVEAT: Work only with 256 color terminal!
red=$(tput setaf 1)
RED=$(tput bold ; tput setaf 1)
blue=$(tput setaf 33)
BLUE=$(tput bold ; tput setaf 33)
cyan=$(tput setaf 6)
CYAN=$(tput bold; tput setaf 6)
NC=$(tput sgr0) # No Color
#---------------
# Shell Prompt
#---------------
if [[ "${DISPLAY#$HOSTNAME}" != ":0.0" && "${DISPLAY}" != ":0" ]]; then
HILIT=${RED} # remote machine: prompt will be partly red
else
HILIT=${BLUE} # local machine: prompt will be partly cyan
fi
# --> Replace instances of \W with \w in prompt functions below
#+ --> to get display of full path name.
function powerprompt() {
_powerprompt() {
_get_svn_data () {
IFS='
'
while read line ; do
case "$line" in
NO)
return 1
;;
URL*)
URL=$(echo $line | sed -ne 's#^URL: ##p')
;;
Repository\ Root:*)
ROOT=$(echo $line | sed -ne 's#^Repository Root: ##p')
;;
Revision:*)
REV=$(echo $line | sed -ne 's#^Revision: ##p')
;;
esac
done < <(LANG=C svn info $file 2>/dev/null || echo NO)
path=$(echo $URL | sed -e 's#^'"$ROOT"'##g')
repo=$(echo $ROOT | awk -F'/' '{ print $NF }')
if [[ $path == /trunk* ]] ; then
tree="trunk"
elif [[ $path == /branches/* ]] ; then
tree="branches: $(echo $path | awk -F'/' '/^\/branches/ { print $3 }')"
fi
# here one defines the SVN part of the prompt
echo "${red}(svn:${repo}-${tree})"
}
LOAD=$(LANG=C uptime|sed -e "s/.*: \([^,]*\).*/\1/" -e "s/ //g")
SVN="$(_get_svn_data)"
}
PROMPT_COMMAND=_powerprompt
case $TERM in
*term | rxvt | screen )
PS1="${HILIT}[\A \$LOAD \$SVN${HILIT}]$NC\n[\u@\h \#] \W > \[\033]0;\u@\h: \w\007\]"
;;
rxvt-unicode*)
PS1=$(printf "${HILIT}[\A \$LOAD \$SVN${HILIT}]$NC\n[\\\\u@\h \#] \W > \[\033]0;\\\\u@\h: \w\007\]")
;;
linux )
PS1="${HILIT}[\A - \$LOAD]$NC\n[\h \#] \w > "
;;
* )
PS1="[\A - \$LOAD]\n[\h \#] \w > "
;;
esac
}
powerprompt # this is the default prompt - might be slow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment