Unless PROMPT_DIRTRIM is explicitly set to 0, force trimming if the
length of the prompt is guesstimated to be more than 2/3 of the
available terminal width.
function __ps1_short() {
local dirtrim=${PROMPT_DIRTRIM//[^0-9]/}
- dirtrim=${dirtrim##0}
- if [ -z "$dirtrim" ]; then
+
+ if [ "${dirtrim:0:1}" = "0" ]; then
echo "$PWD"
return $1
fi
+
+ dirtrim=${dirtrim##0}
+ if [ -z "$dirtrim" ]; then
+ local prompt="$USER$HOSTNAME$PWD"
+ local width=$(((COLUMNS*2)/3))
+ if [ ${#prompt} -le ${width:-53} ]; then
+ echo "$PWD"
+ return $1
+ else
+ dirtrim=1
+ fi
+ fi
+
local dirname=${PWD##*/}
local basename=${PWD%/$dirname}
local reversed=
fi
n=$((n+1))
done
+
echo "$short/$dirname"
return $1
}