Skip to content

Instantly share code, notes, and snippets.

@kethinov
Created May 11, 2016 22:38
Show Gist options
  • Save kethinov/f369eb4adf82c5f6ada5b57372fcf218 to your computer and use it in GitHub Desktop.
Save kethinov/f369eb4adf82c5f6ada5b57372fcf218 to your computer and use it in GitHub Desktop.
PWDMAXLENGTH=30
PROMPTTRUNCSYM="..."
# Change the window title of X terminals
case $TERM in
xterm*|rxvt|Eterm|eterm)
PROMPT_COMMAND_TITLE="\033]0;USER@HOSTNAME:CURRDIR\007"
;;
screen)
PROMPT_COMMAND_TITLE='\033_USER@HOSTNAME:CURRDIR\033\\'
;;
esac
PROMPT_COMMAND=promptcommand
function promptcommand {
TMPTITLE=${PROMPT_COMMAND_TITLE/USER/$USER}
TMPHOST=${HOSTNAME%%.*}
TMPTITLE=${TMPTITLE/HOSTNAME/$TMPHOST}
TMPDIR=${PWD/$HOME/~}
TMPTITLE=${TMPTITLE/CURRDIR/$TMPDIR}
echo -ne $TMPTITLE
if [ ${#TMPDIR} -gt $PWDMAXLENGTH ]
then
PWDOFFSET=$(( ${#TMPDIR} - $PWDMAXLENGTH + ${#PROMPTTRUNCSYM} ))
TMPDIR="${PROMPTTRUNCSYM}${TMPDIR:$PWDOFFSET:$PWDMAXLENGTH}"
fi
case $TERM in
sun)
PS1="\[\e[32;1m\]\u@\[\e[36;1m\]\h:\[\e[31;1m\w>\[\e[0m\] "
;;
*)
PS1="\[\033[32;1m\]\u\[\033[0m\]@\[\033[36;1m\]\h\[\033[0m\]:\[\033[31;1m\]$TMPDIR\[\033[0m\]> "
;;
esac
unset TMPTITLE
unset TMPDIR
unset TMPHOST
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment