zsh-workers
 help / color / mirror / code / Atom feed
From: "Jörg Sommer" <joerg@alea.gnuu.de>
To: zsh-workers@zsh.org
Subject: [PATCH] run-help alias with variables, run-help-git better alias support
Date: Mon, 8 May 2017 18:24:41 +0200	[thread overview]
Message-ID: <20170508162441.guz2q4untduwgojt@alea.gnuu.de> (raw)


[-- 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 --]

                 reply	other threads:[~2017-05-08 16:32 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170508162441.guz2q4untduwgojt@alea.gnuu.de \
    --to=joerg@alea.gnuu.de \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).