From: Iain Patterson Date: Tue, 2 Feb 2016 10:59:11 +0000 (+0000) Subject: Set PROMPT_DIRTRIM dynamically. X-Git-Url: http://git.iain.cx/?a=commitdiff_plain;h=936cca97dc46219cca23e91ea9411eec359432cf;p=profile.git Set PROMPT_DIRTRIM dynamically. 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. --- diff --git a/.profile.d/ps1.bashrc b/.profile.d/ps1.bashrc index 0283611..0667d0f 100644 --- a/.profile.d/ps1.bashrc +++ b/.profile.d/ps1.bashrc @@ -201,11 +201,24 @@ function __ps1_colon() { 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= @@ -223,6 +236,7 @@ function __ps1_short() { fi n=$((n+1)) done + echo "$short/$dirname" return $1 }