zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] run-help alias with variables, run-help-git better alias support
@ 2017-05-08 16:24 Jörg Sommer
  0 siblings, 0 replies; only message in thread
From: Jörg Sommer @ 2017-05-08 16:24 UTC (permalink / raw)
  To: zsh-workers


[-- Attachment #1.1: Type: text/plain, Size: 678 bytes --]

Hi,

both patches are also available through my repository
https://github.com/jo-so/zsh.git

====================
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 T='LC_ALL=C true'
% run-help T

====================
run-help-git: Print alias and skip shell commands

Print the definition of the git-alias like run-help does for shell
aliases. Git handles an alias starting with ! as a shell command. Hence,
there's no man-page for it.

Bye, Jörg

[-- Attachment #1.2: 0001-run-help-Support-variables-in-aliases.patch --]
[-- Type: text/x-diff, Size: 1694 bytes --]

From a184bff4e75445150ce75e7e273bd7bc1b0d273c Mon Sep 17 00:00:00 2001
Message-Id: <a184bff4e75445150ce75e7e273bd7bc1b0d273c.1494259970.git.joerg@alea.gnuu.de>
From: =?UTF-8?q?J=C3=B6rg=20Sommer?= <joerg@alea.gnuu.de>
Date: Mon, 8 May 2017 17:46:52 +0200
Subject: [PATCH 1/2] 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 T='LC_ALL=C true'
% run-help T
---
 Functions/Misc/run-help | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/Functions/Misc/run-help b/Functions/Misc/run-help
index e351dd6a6..4df689192 100644
--- a/Functions/Misc/run-help
+++ b/Functions/Misc/run-help
@@ -56,13 +56,16 @@ 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}
-	;;
     (*( is an alias)*)
-	[[ ${what[(w)6]:t} != ${what[(w)1]} ]] &&
-	  run_help_orig_cmd=${what[(w)1]} run-help ${what[(w)6]:t}
+        local cmd_idx=6
+        while [[ ${what[(w)$cmd_idx]} == *=* ]]
+        do
+            (( ++cmd_idx ))
+        done
+        [[ ${what[(w)$cmd_idx]} == (noglob|nocorrect) ]] &&
+            (( ++cmd_idx ))
+	[[ ${what[(w)$cmd_idx]:t} != ${what[(w)1]} ]] &&
+	  run_help_orig_cmd=${what[(w)1]} run-help ${what[(w)$cmd_idx]:t}
 	;;
     (*( is a * function))
 	case ${what[(w)1]} in
-- 
2.11.0


[-- Attachment #1.3: 0002-run-help-git-Print-alias-and-skip-shell-commands.patch --]
[-- Type: text/x-diff, Size: 1230 bytes --]

From fe825e405b5bd9358718c2e5f1b0ba20b7d7cb9a Mon Sep 17 00:00:00 2001
Message-Id: <fe825e405b5bd9358718c2e5f1b0ba20b7d7cb9a.1494259970.git.joerg@alea.gnuu.de>
In-Reply-To: <a184bff4e75445150ce75e7e273bd7bc1b0d273c.1494259970.git.joerg@alea.gnuu.de>
References: <a184bff4e75445150ce75e7e273bd7bc1b0d273c.1494259970.git.joerg@alea.gnuu.de>
From: =?UTF-8?q?J=C3=B6rg=20Sommer?= <joerg@alea.gnuu.de>
Date: Mon, 8 May 2017 18:05:54 +0200
Subject: [PATCH 2/2] run-help-git: Print alias and skip shell commands

Print the definition of the git-alias like run-help does for shell
aliases. Git handles an alias starting with ! as a shell command. Hence,
there's no man-page for it.
---
 Functions/Misc/run-help-git | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Functions/Misc/run-help-git b/Functions/Misc/run-help-git
index ce94d0d02..3c8e6a150 100644
--- a/Functions/Misc/run-help-git
+++ b/Functions/Misc/run-help-git
@@ -3,6 +3,8 @@ if [ $# -eq 0 ]; then
 else
     local al
     if al=$(git config --get "alias.$1"); then
+        builtin print -r "${run_help_orig_cmd:-git} $1 is a git-alias for $al"
+        [[ $al == !* ]] && return
         1=${al%% *}
     fi
     man git-$1
-- 
2.11.0


[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-05-08 16:32 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-08 16:24 [PATCH] run-help alias with variables, run-help-git better alias support Jörg Sommer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).