JasonDaly.name

PHP, Ruby, Symfony, Rails, Doctrine, MooTools. Web Development.
May 26, 2009

Making PROMPT_COMMAND More Informative

On Mac/Linux the shell’s command prompt is typically fairly uninformative, displaying only the top level of the current working directory path. If you are currently at /home/me/sites/mysite, the prompt might look something like

[mysite]$ ...

This isn’t as useful as it could be. LinDesk details multiple ways to make the command prompt more informative. Based on the information there I now have the following PROMPT_COMMAND set in my ~/.bash_profile.

PROMPT_COMMAND='DIR=`pwd|sed -e "s!$HOME!~!"`; if [ ${#DIR} -gt 30 ]; then CurDir=${DIR:0:12}...${DIR:${#DIR}-15}; else CurDir=$DIR; fi'
PS1="[\$CurDir] \$ "

This now makes the same directory path above for /home/me/sites/mysite look like this

[/home/me/s...ite/public_html] $

Tags: bash command prompt tips