X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=.profile.d%2Fps1.bashrc;h=991095bcca59aad63effe4eba9dcfef4b4e5c407;hb=730f97068308dceebb2d269070701533ec22a9c9;hp=0667d0f153122a7b33fa0e0e501d55f3c4594587;hpb=936cca97dc46219cca23e91ea9411eec359432cf;p=profile.git diff --git a/.profile.d/ps1.bashrc b/.profile.d/ps1.bashrc index 0667d0f..991095b 100644 --- a/.profile.d/ps1.bashrc +++ b/.profile.d/ps1.bashrc @@ -200,27 +200,29 @@ function __ps1_colon() { } function __ps1_short() { + local home=${HOME%%/} + local pwd=${PWD/#$home/\~} local dirtrim=${PROMPT_DIRTRIM//[^0-9]/} if [ "${dirtrim:0:1}" = "0" ]; then - echo "$PWD" + echo "$pwd" return $1 fi dirtrim=${dirtrim##0} if [ -z "$dirtrim" ]; then - local prompt="$USER$HOSTNAME$PWD" + local prompt="$USER$HOSTNAME$pwd" local width=$(((COLUMNS*2)/3)) if [ ${#prompt} -le ${width:-53} ]; then - echo "$PWD" + echo "$pwd" return $1 else dirtrim=1 fi fi - local dirname=${PWD##*/} - local basename=${PWD%/$dirname} + local dirname=${pwd##*/} + local basename=${pwd%/$dirname} local reversed= local component for component in ${basename//\// }; do @@ -229,14 +231,16 @@ function __ps1_short() { local n=1 local short= for component in $reversed; do + [ $n = 1 -a "$PWD" = "$pwd" ] || short="/$short" if [ $n -ge $dirtrim ]; then - short="/${component:0:1}$short" + short="${component:0:1}$short" else - short="/$component$short" + short="$component$short" fi n=$((n+1)) done + [ "${short:0:1}" = "~" ] || short="/$short" echo "$short/$dirname" return $1 }