Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For example working in:


would appear as:

share|improve this question
up vote 3 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

Here is my go at it, based on Mat's answer. Avoids problems in corner cases such as / and ~.

PS1='`echo "${PWD%/*}" | sed -e "s;\(/.\)[^/]*;\1;g"`/${PWD##*/} \$ '

Replace . with .. to display 2 letters.

share|improve this answer

Your Answer


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.