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:
/some_really_long_path/going/to/some_place gets changed to
...ng_path/going/to/some_place
so the prompt would look like:
-hostname:...ng_path/going/to/some_place- username$
thanks in advance...
PROMPT_COMMAND='if [ ${#PWD} -gt 30 ]
then PS1="-\h:...${PWD: -27}\u$ "
else PS1="-\h:\w- \u$ "
fi'
--
Chris F.A. Johnson <http://cfaj.freeshell.org>
==================================================================
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
<http://www.torfree.net/~chris/books/cfaj/ssr.html>
If you have bash3, then the following will do what you want, after you put
in a few more question-marks.
PS1='-\h:${PWD/#??????????????*/...${PWD#${PWD%??????????????}}}- \u\$ '
The first set of question-marks determine the length where the prompt is
changed, and the second set determine how many characters of the name are
displayed.
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.
I ended up going with Chris F.A. Johnson's solution. I like the idea
of having the PROMPT_COMMAND do all the checking 'work'. Thanks
Chris!
Let another script do the work for you...
http://www.dotfiles.com/files/3/183_.bash_prompt
http://bashish.sourceforge.net # "bashish.bash"
http://sunsite.bilkent.edu.tr/pub/linux/dotfile/ # "Dotfile
Generator.tcl"
http://asciipr0n.com/fp/ibpconf.sh-6.2.tar.gz # "ibpconf.bash"
For bash profiles in general, a fine place to look is:
http://www.dotfiles.com/files/3/
=Brian