Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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$
share|improve this question

2 Answers 2

up vote 2 down vote accepted

Yes, it is possible and has been done here.

share|improve this answer

Try this:

export PS1='$(echo $(dirname \w)|sed -e "s;\(/.\)[^/]*;\1;g")/$(basename \w) $ '
share|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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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