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

[PATCH 1/4] run-help: Support variables in aliases



If the alias definition starts with a variable assignment, run-help fails,
because it sees the variable assignment as command. Hence, skip all
variable assignments and noglob|nocorrect thereafter.

Example:

% alias LCC='LC_ALL=C'
% alias T='LCC true'
% run-help T
---
 Functions/Misc/run-help | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/Functions/Misc/run-help b/Functions/Misc/run-help
index 462044b72..438f76122 100644
--- a/Functions/Misc/run-help
+++ b/Functions/Misc/run-help
@@ -56,13 +56,28 @@ do
     [[ -n $noalias && $what = *" is an alias "* ]] && continue
     builtin print -r $what
     case $what in
-    (*( is an alias for (noglob|nocorrect))*)
-	[[ ${what[(w)7]:t} != ${what[(w)1]} ]] &&
-	  run_help_orig_cmd=${what[(w)1]} run-help ${what[(w)7]:t} ${(z)${what[(w)8,-1]}}
-	;;
     (*( is an alias)*)
-	[[ ${what[(w)6]:t} != ${what[(w)1]} ]] &&
-	  run_help_orig_cmd=${what[(w)1]} run-help ${what[(w)6]:t} ${(z)${what[(w)7,-1]}}
+        local expansion=( ${${=what}[6,-1]} )
+        while true
+        do
+            if [[ $expansion[1] == *=* ]]
+            then
+                shift expansion
+            elif [[ $expansion[1] == (noglob|nocorrect) ]]
+            then
+                shift expansion
+                break
+            elif [[ $expansion[1] != $1 ]] && alias $expansion[1] >/dev/null
+            then
+                expansion=( ${=$(builtin whence $expansion[1])} $expansion[2,-1] )
+            else
+                break
+            fi
+        done
+
+        expansion[1]=$expansion[1]:t
+        [[ $expansion[1] != ${what[(w)1]} ]] &&
+          run_help_orig_cmd=${what[(w)1]} run-help $expansion[@]
 	;;
     (*( is a * function))
 	case ${what[(w)1]} in
-- 
2.40.1





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