Thursday, December 11, 2008

Saving prompt space

When using vi's :tabe command (opens a file in another "tab" in the same terminal window), i noticed it shows the path to the file in an abbreviated form: /home/kees/path/to/file becomes /h/k/p/t/file. This saves space, while preserving some information about where you are.

This seems like a useful feature in a prompt as well. For example, when \u@\h \w \$ yields something as long as ~/Documents/manuals/plone/code for the aspeli book/optilux-code-2007-10-21/chapter-09/examples, you're likely to get annoyed after a while.

So now my PS1="\u@\h \$(abbr_path.sh) \$ ", and the script is pwd | perl -p -e 's/([^\/])[^\/]*[\/]/$1\//g'. Let's see how long this setup keeps me happy. I might also replace the regexp with 's/([^\/]{1,3})[^\/]*[\/]/$1\//g' if i want more than one character per directory.

No comments: