I liked the spwd idea and ended up adjusting it to be a bit more precise.
I just did some more testing with it to make sure it handled complicated directories
without choking (though if they embed control chars, I don't filter them out... )...
But rather than just looking at the number of dirs and displaying the
whole path if <=3 elements or ..., like the current one does --
this one uses a progressive shortening, based on the length of the
directory names. It aims to keep the total length down to 1/2 the # columns
(so 40 on a standard screen)...
Despite my many manipulations of the path, It works with dir paths like:
dp> ll
total 0
drwxrwsr-x 2 6 Jul 1 13:42 ^ difficult dir(to) "parse" ['correctly'],
*{maybe}? ~; or #not/
drwxrwsr-x 2 6 Jul 1 14:35 _^ d r(2)s['rt'],*{m}; #r ~ ! \\not?/
The first one is too long to display on an 80 column screen, but
it displays (weirdly) when used (it has a line-feed in the dir name):
Ishtar:law/dp/^ difficult dir(to) "parse" ['correctly'],
*{maybe}? ~; or #not> _
Ishtar:law/dp> cd _\^\ d\ r\(2\)s\[\'rt\'\]\,\*\{m\}\;\ #r\ ~\ \!\ \\\\not\?/
Ishtar:.../_^ d r(2)s['rt'],*{m}; #r ~ ! \not?> _
The cut-down in paths was put in an array:
alias int=declare\ -i _e=echo _pf=printf exp=export ret=return
exp __dpf__='local -a PF=(
"/$1/$2/$3/../\${$[$#-1]}/\${$#}"
"/$1/$2/../\${$[$#-1]}/\${$#}"
"/$1/../\${$[$#-1]}/\${$#}"
"/$1/../\${$#}"
".../\${$#}"
"..." )'
It tries to use a bit of the first part and some of the last part...
Using more if you have dirs like "a/b/c...y/z".
The function is:
function spwd () { \
(($#)) || { _e "spwd called with null arg"; return 1; }; \
int w=COLUMNS/2 ;\
( _pf -v _p "%s" "$1" ; export IFS=/ ;\
set $_p; shift; unset IFS ;\
t="${_p#${HOME%${USER}}}";
int tl=${#t} ;\
if (($#<=6 && tl