Limit the length of the displayed path in the Bash prompt. Loosely based
on the ideas at:
http://www.faqs.org/docs/Linux-HOWTO/Bash-Prompt-HOWTO.html#AEN768
Two mechanisms are presented (one of them is commented out):
1. Trim the path to the last 30 characters, and cut off a partial
leading directory name
2. Just display the last three directory names in the path
Put the following in your .bashrc:
# Replace the \w in the default Ubuntu prompt with $newPWD
if [ "$color_prompt" = yes ]; then
#PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\...@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$
'
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\...@\h\[\033[00m\]:\[\033[01;34m\]$newPWD\[\033[00m\]\$
'
else
#PS1='${debian_chroot:+($debian_chroot)}...@\h:\w\$ '
PS1='${debian_chroot:+($debian_chroot)}...@\h:$newPWD\$ '
fi
function prompt_command {
local trunc_string="..."
newPWD="${PWD/$HOME/~}"
# Remove leading directories beyond a certain length
# Strip any partial directory names
local pwdmaxlen=30
if [ ${#newPWD} -gt $pwdmaxlen ]; then
local pwdoffset=$(( ${#newPWD} - $pwdmaxlen ))
newPWD="${newPWD:$pwdoffset:$pwdmaxlen}"
newPWD="${trunc_string}/${newPWD#*/}"
fi
## Remove leading directories, leaving a maximum of three
#remove_dirs="${newPWD%/*/*/*}"
#if [[ ${remove_dirs} != $newPWD ]]; then
# newPWD=${trunc_string}${newPWD/$remove_dirs\//}
#fi
# If this is an xterm set the title to u...@host:dir
case "$TERM" in
xterm*|rxvt*)
echo -ne "\033]0;${us...@${hostname}: ${PWD/$HOME/~}\007"
;;
*)
;;
esac
}
export PROMPT_COMMAND=prompt_command
Douglas.
=======================================================================
This email, including any attachments, is only for the intended
addressee. It is subject to copyright, is confidential and may be
the subject of legal or other privilege, none of which is waived or
lost by reason of this transmission.
If the receiver is not the intended addressee, please accept our
apologies, notify us by return, delete all copies and perform no
other act on the email.
Unfortunately, we cannot warrant that the email has not been
altered or corrupted during transmission.
=======================================================================