For example working in:

/home/stuart/src/project/com/example/package
/usr/lib/python2.6

would appear as:

~/s/p/c/e/package$ 
/u/l/python2.6$
link|improve this question
feedback

2 Answers

up vote 2 down vote accepted

Yes, it is possible and has been done here.

link|improve this answer
feedback

Try this:

export PS1='$(echo $(dirname \w)|sed -e "s;\(/.\)[^/]*;\1;g")/$(basename \w) $ '
link|improve this answer
+1 very elegant and works great (Ubuntu) – Linker3000 Apr 15 '11 at 12:09
Great thanks. I've updated it to: export PS1='$(echo $(dirname \w)|sed -e "s;\(/\.\?.\)[^/]*;\1;g" -e "s;/h/s;~;")/\W\$ ' So that dot dirs keep a "." and a character. I also replace "/h/s" (/home/stuart) with a "~". – Stuart K Apr 17 '11 at 9:19
Second update: export PS1='$(echo $(dirname $(echo \w | sed "s;$HOME;~;"))/ |sed -e "s;\(/\.\?.\)[^/]*;\1;g" -e "s;/h/s;~;" -e "s;\./;;")\W\$ ' Adds some more hacks so that it looks good in the home dir. – Stuart K Apr 17 '11 at 9:33
And now I've discovered there are far too many edge cases for this approach to work the way I want (root dir, in home dir, being below home dir). It's still very elegant though! – Stuart K Apr 17 '11 at 9:42
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.