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
Another solution with only bash internals, no use of sed
shortpath()
{
dir=${1%/*} && last=${1##*/}
res=$(for i in ${dir//\// } ; do echo -n "${i:0:3}../" ; done)
echo "/$res$last"
}
My previous solution, with bash and sed. it cut each dir in 3 first caracters and add '..' like this: /hom../obo../tmp../exa../bas../
shortpath()
{
dir=$(dirname $1)
last=$(basename $1)
v=${dir//\// } # replace / by in path
t=$(printf "echo %s | sed -e 's/^\(...\).*$/\\\1../' ; " $v)
# prepare command line, cut names to 3 char and add '..'
a=$(eval $t)
# a will contain list of 3 char words ended with '..' ans separated with ' '
echo " "$a"/"$last | sed -e 's/ /\//g'
}