|
shortpwd is a small Python program for producing a pleasantly abbreviated version of a Unix system path. It was written to be used as part of the bash shell PS1 variable, which defines a user's shell prompt, since a standard PS1 which contains the current working directory string will either become extremely long in deep directory trees or won't recognise the user's home directory with the customary tilde (~).
Here's a typical usage of shortpwd in the PS1 variable, as might be placed in a user's $HOME/.bashrc file:
PESC="\033"
PSTYLE="m"
#PROMPT="\u@\h:\w" # typical default prompt
PROMPT="\u@\h:\`shortpwd 2> /dev/null || echo '\\w'\`" # use of shortpwd
PCOLOUR="0;31"
PBLUE="0;34"
export PS1="\[$PESC[$PCOLOUR$PSTYLE\]$PROMPT\[$PESC[$PBLUE$PSTYLE\]\$\[$PESC[0m\] "
with the result that being deep in a directory tree gets truncated neatly, while still showing as many of the parent directories as possible, and indicating if the current directory is a descendant of the home directory. Here's an example:
buckley@h6:~$ cd proj/cedar/hepdata/java/cedar/hepdata/model/ buckley@h6:~/.../hepdata/model$The maximum number of allowable characters can be easily configured using the "-l" command line switch or by editing the default in the file. The typical lag on the command line is not noticeable, unless e.g you hold down the return key. Personally, I think it's great :-)