Fix short path in prompt.
authorIain Patterson <me@iain.cx>
Sat, 8 May 2021 08:45:44 +0000 (10:45 +0200)
committerIain Patterson <me@iain.cx>
Sat, 8 May 2021 08:49:46 +0000 (10:49 +0200)
.profile.d/ps1.bashrc

index 80ad1da..7c4cf2c 100644 (file)
@@ -238,7 +238,7 @@ function __ps1_short() {
   local pwd=${PWD/#$home/\~}
   local dirtrim=${PROMPT_DIRTRIM//[^0-9]/}
 
-  if [ "${dirtrim:0:1}" = "0" ]; then
+  if [ "${dirtrim:0:1}" = "0" -o "$PWD" = "$HOME" ]; then
     echo "$pwd"
     return $1
   fi
@@ -265,7 +265,7 @@ function __ps1_short() {
   local n=1
   local short=
   for component in $reversed; do
-    [ $n = 1 -a "$PWD" = "$pwd" ] || short="/$short"
+    [ $n = 1 ] || short="/$short"
     if [ $n -ge $dirtrim ]; then
       short="${component:0:1}$short"
     else
@@ -274,7 +274,7 @@ function __ps1_short() {
     n=$((n+1))
   done
 
-  [ "${short:0:1}" = "~" ] || short="/$short"
+  [ "${short:0:1}" = "~" -o -z "$basename" ] || short="/$short"
   echo "$short/$dirname"
   return $1
 }