I am customizing my PS1 prompt, specifically the $PWD part which is delimited by /'s
among several things I like having the current directory.
However if the directory is too long I'd like to have beginning...ending
For example, instead of
otherstuff:~/apps/webs/2014/area1/groupa/current:other_stuff $ I'd like to have the first directories and the last two, i.e.
otherstuff:~/apps/webs/.../groups/current:other_stuff $ It should handle when they partially overlap, i.e.
otherstuff:~/apps/webs/2014:other_stuff $ -> otherstuff:~/apps/webs/2014:other_stuff $ and when they are the same, i.e.
otherstuff:~/apps/webs/:other_stuff $ -> otherstuff:~/apps/webs/:other_stuff $ I tried various substrings if $PWD using {}, () and {} but can't get the format right.
Update - I used the information in guidos answer (accepted) to put together this:
parse_git_branch () { git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' } PS1='\033[01;31m\]\t\033[00m\]:' PS1=$PS1'\[\033[01;32m\]\u\033[00m\]:\033[01;34m\]' PS1=$PS1'`pwd | sed "s#\(/[^/]\+/[^/]\+/\).*\(/[^/]\+/[^/]\+\)/\?#\1...\2#g"`' PS1=$PS1'\033[00m\]:\033[01;33m\]$(parse_git_branch)\[\033[00m\]\n\$ ' which yields:

A sad amount of the code is repeated \033[00m\]:'s for the 3 white colon seperator !