I sometimes find having the full directory path in the prompt to be overwhelming, so I've created this small bash function which shows just the last two parts of the path:
short_dir () { if [ "$PWD" = "$HOME" ]; then echo '~' else the_dir=`dirname "$PWD"`; the_base=`basename "$PWD"`; the_dir_base=`basename "$the_dir"`; if [ "$the_dir_base" = '/' ]; then the_dir_base=""; fi echo "$the_dir_base/$the_base" fi }Add a call to this to your prompt, don't forget to escape the backquotes:
export PS1="\`short_dir\`\$ "
So, if your current directory is /usr/local/man/man1, your prompt would look like:
man/man1$
You can, of course, sprinkle in other bash prompt special characters, such as "\h" for the hostname:
export PS1="(\h) \`short_dir\`\$ "
produces:
(myhost) man/man1$
Tags: