Skip to content

Instantly share code, notes, and snippets.

@codekitchen
Created June 10, 2015 18:08
Show Gist options
  • Save codekitchen/e3d0090b861b3c8efb1d to your computer and use it in GitHub Desktop.
Save codekitchen/e3d0090b861b3c8efb1d to your computer and use it in GitHub Desktop.
truncated_pwd () {
local pwdmaxlen=45
local trunc_symbol="…"
local dir=${PWD##*/}
pwdmaxlen=$(( ( pwdmaxlen < ${#dir} ) ? ${#dir} : pwdmaxlen ))
NEW_PWD=${PWD/#$HOME/\~}
local pwdoffset=$(( ${#NEW_PWD} - pwdmaxlen ))
if [ ${pwdoffset} -gt "0" ]
then
NEW_PWD=${NEW_PWD:$pwdoffset:$pwdmaxlen}
NEW_PWD=${trunc_symbol}/${NEW_PWD#*/}
fi
echo $NEW_PWD
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment