I implemented a prompt path shortener for bash to be included in the PS1 environment variable, which shortens the working directory into something more compact but still descrip
This one is 20 or so characters shorter than my other answer:
_dir_chomp () { local p=${1/#$HOME/\~} b s s=${#p} while [[ $p != "${p//\/}" ]]&&(($s>$2)) do p=${p#/} [[ $p =~ \.?. ]] b=$b/${BASH_REMATCH[0]} p=${p#*/} ((s=${#b}+${#p})) done echo ${b/\/~/\~}${b+/}$p }