extend gp_truncate_pwd to accept parameter with max pwd length

If length is passed as a parameter, the given length will be used to
truncate the pwd. If nothing is specified it defaults to 1/3 of
the terminal width.
master
Stephan Knauss 9 years ago
parent 6645a82003
commit 85de63d504
  1. 3
      gitprompt.sh

@ -585,10 +585,11 @@ function is_function {
}
# Helper function that truncates $PWD depending on window width
# Optionally specify maximum length as parameter (defaults to 1/3 of terminal)
function gp_truncate_pwd {
local tilde="~"
local newPWD="${PWD/#${HOME}/${tilde}}"
local pwdmaxlen=$((${COLUMNS:-80}/3))
local pwdmaxlen=${1:-$((${COLUMNS:-80}/3))}
[ ${#newPWD} -gt $pwdmaxlen ] && newPWD="...${newPWD:3-$pwdmaxlen}"
echo -n "$newPWD"
}

Loading…
Cancel
Save