Skip to content

Instantly share code, notes, and snippets.

@aherrman
Created September 3, 2010 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aherrman/563855 to your computer and use it in GitHub Desktop.
Save aherrman/563855 to your computer and use it in GitHub Desktop.
# Echoes the name of the current screen, if any
function getScreenName {
if [ ${STY:-""} == "" ]; then
screen_name=""
else
screen_name="(`echo "${STY}" | sed 's/^[^\.]*\.//'`)"
fi
echo $screen_name
}
# Echoes the string to use as the colored prompt
function getColoredPrompt {
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
echo '${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[01;36m\]$(getScreenName)\[\033[00m\]:\[\033[01;35m\]\w\[\033[00m\]\$ '
}
# Echoes the string to use as the uncolored prompt
function getUncoloredPrompt {
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
echo '${debian_chroot:+($debian_chroot)}\u@\h$(getScreenName):\w\$ '
}
# Sets the prompt to either the colored or uncolored, depending on the current
# environment
function setPrompt() {
# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
debian_chroot=$(cat /etc/debian_chroot)
fi
# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
xterm*) color_prompt=yes;;
esac
force_color_prompt=yes
if [ -n "$force_color_prompt" ]; then
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
# We have color support; assume it's compliant with Ecma-48
# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
# a case would tend to support setf rather than setaf.)
color_prompt=yes
else
color_prompt=
fi
fi
if [ "$color_prompt" = yes ]; then
PS1="$(getColoredPrompt)"
else
PS1="$(getUncoloredPrompt)"
fi
unset color_prompt force_color_prompt
}
# Sets the title of the current xterm to mirror the prompt
function setTitleToPrompt {
# Reset the prompt in case the title was already added to it.
setPrompt
# We need to use the uncolored prompt for the title as the color escape
# sequences confuse it.
case "$TERM" in
xterm*|rxvt*)
PS1="\[\e]0;$(getUncoloredPrompt)\a\]$PS1"
;;
*)
;;
esac
}
function setTitle {
# if setTitleToPrompt was called then we need to clear the title-setting bits
# from the prompt, otherwise this won't take affect.
setPrompt
echo -en "\033]0;$1\007"
}
# Default to having the current prompt be the xterm name
setTitleToPrompt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment