Tue, 12 Jul 2005 15:04:42 -0700, juicymixx@mailinator.com wrote:
hey, I'd like to customize my bash prompt a bit
currently I have:
PS1="-\h:\w- \u$ "
the problem I have is sometimes I get pretty deep into my directory
structure, and some of my directory names are pretty long. Is there
some way to change the \w in my prompt to: 1) if the directory structure
is less than 30 characters, just display it
2) if the directory structure is more than 30 characters, change it to
display three dots (like an ellipsis) and the last 27 characters of the
path
for instance:
/ gets changed to
ng_path/going/to/some_place
so the prompt would look like:
username$
If you have bash3, then the following will do what you want, after you put
in a few more question-marks, and change the number
PS1='-\h:${PWD/#???*/${PWD: -9}}- \u\$ '
The question-marks determine the length where the prompt is changed, and
the -9 determine how many characters of the name are displayed.