Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

[PATCH] Fix VCS_INFO_reposub's command expansion

Reported-by: Marco Hinz <mh.codebro@xxxxxxxxx>

The problem, as others mentioned, is that $(...) is subject
to word-splitting. I think we should fix it like is done
below. Even though in a variable assignment:


There is *no* word-splitting, I think the use of the double quotes
is warranted, since it underlines the intend. Also, using a
temporary variable like this should save a stat() call.

 Functions/VCS_Info/VCS_INFO_reposub | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/Functions/VCS_Info/VCS_INFO_reposub b/Functions/VCS_Info/VCS_INFO_reposub
index 1c16f0e..8ebc90b 100644
--- a/Functions/VCS_Info/VCS_INFO_reposub
+++ b/Functions/VCS_Info/VCS_INFO_reposub
@@ -3,11 +3,12 @@
 ## Distributed under the same BSD-ish license as zsh itself.
 setopt localoptions extendedglob NO_shwordsplit
-local base=${1%%/##}
+local base=${1%%/##} tmp
-[[ $(pwd -P) == ${base}/* ]] || {
+tmp="$(pwd -P)"
+[[ $tmp == ${base}/* ]] || {
     printf '.'
     return 1
-printf '%s' ${$(pwd -P)#$base/}
+printf '%s' ${tmp#$base/}
 return 0

Messages sorted by: Reverse Date, Date, Thread, Author