From 065ab44ac4eaa42fd12abc224d78e8fd7efb9171 Mon Sep 17 00:00:00 2001 From: Mark Crossfield Date: Thu, 22 Aug 2019 14:07:43 +0100 Subject: [PATCH 1/3] Fix #262 by separating new PROMPT_COMMAND commands --- z.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/z.sh b/z.sh index c78f3cb..957bfe5 100644 --- a/z.sh +++ b/z.sh @@ -247,6 +247,11 @@ elif type complete >/dev/null 2>&1; then [ "$_Z_NO_PROMPT_COMMAND" ] || { # populate directory list. avoid clobbering other PROMPT_COMMANDs. grep "_z --add" <<< "$PROMPT_COMMAND" >/dev/null || { + # Check if there are existing PROMPT_COMMANDs that are not terminated with a semicolon + if [[ "$PROMPT_COMMAND" =~ ^[^\ ]+ ]] && ! [[ "$PROMPT_COMMAND" =~ ^.*\;\ *$ ]] + then # terminate it + PROMPT_COMMAND="$PROMPT_COMMAND; " + fi PROMPT_COMMAND="$PROMPT_COMMAND"$'\n''(_z --add "$(command pwd '$_Z_RESOLVE_SYMLINKS' 2>/dev/null)" 2>/dev/null &);' } } From 296d37e7dadfe3e02ad6670b0fde1cc784422306 Mon Sep 17 00:00:00 2001 From: Mark Crossfield Date: Thu, 22 Aug 2019 17:07:50 +0100 Subject: [PATCH 2/3] Prepend rather than append to PROMPT_COMMAND This should avoid clobbering without needing to terminate other commands. --- z.sh | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/z.sh b/z.sh index 957bfe5..aa82869 100644 --- a/z.sh +++ b/z.sh @@ -247,12 +247,7 @@ elif type complete >/dev/null 2>&1; then [ "$_Z_NO_PROMPT_COMMAND" ] || { # populate directory list. avoid clobbering other PROMPT_COMMANDs. grep "_z --add" <<< "$PROMPT_COMMAND" >/dev/null || { - # Check if there are existing PROMPT_COMMANDs that are not terminated with a semicolon - if [[ "$PROMPT_COMMAND" =~ ^[^\ ]+ ]] && ! [[ "$PROMPT_COMMAND" =~ ^.*\;\ *$ ]] - then # terminate it - PROMPT_COMMAND="$PROMPT_COMMAND; " - fi - PROMPT_COMMAND="$PROMPT_COMMAND"$'\n''(_z --add "$(command pwd '$_Z_RESOLVE_SYMLINKS' 2>/dev/null)" 2>/dev/null &);' + PROMPT_COMMAND="$'\n''(_z --add "$(command pwd '$_Z_RESOLVE_SYMLINKS' 2>/dev/null)" 2>/dev/null &);'$PROMPT_COMMAND" } } fi From c2692dd1f52f302a1bd0b78d6213e4b828603f52 Mon Sep 17 00:00:00 2001 From: Mark Crossfield Date: Thu, 22 Aug 2019 17:16:19 +0100 Subject: [PATCH 3/3] Move quote to fix issue with bash expansion syntax --- z.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/z.sh b/z.sh index aa82869..55fa3ec 100644 --- a/z.sh +++ b/z.sh @@ -247,7 +247,7 @@ elif type complete >/dev/null 2>&1; then [ "$_Z_NO_PROMPT_COMMAND" ] || { # populate directory list. avoid clobbering other PROMPT_COMMANDs. grep "_z --add" <<< "$PROMPT_COMMAND" >/dev/null || { - PROMPT_COMMAND="$'\n''(_z --add "$(command pwd '$_Z_RESOLVE_SYMLINKS' 2>/dev/null)" 2>/dev/null &);'$PROMPT_COMMAND" + PROMPT_COMMAND=$'\n''(_z --add "$(command pwd '$_Z_RESOLVE_SYMLINKS' 2>/dev/null)" 2>/dev/null &);'"$PROMPT_COMMAND" } } fi