zsh-workers
 help / color / mirror / code / Atom feed
* How to prevent alias expansion
@ 2009-01-04 15:57 Jörg Sommer
  2009-01-04 18:33 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Jörg Sommer @ 2009-01-04 15:57 UTC (permalink / raw)
  To: zsh-workers

Hi,

I've a problem with alias expansion. When using run-help and an global
alias for redirect to /dev/null the command fails.

% alias -g DN='>/dev/null'
% git show DN<ESC h>
<empty output>

I propose this patch:
commit f7d81342f5d1a17879cbee0c2d0e602451f21e19
Author: Jörg Sommer <joerg@alea.gnuu.de>
Date:   Sun Jan 4 16:50:00 2009 +0100

    Double‐quote the argument of specialized run-help functions
    
    Quoting the arguments of the run-help-$CMD functions only one time makes
    eval expands them. In the case of a global alias DN='>/dev/null' the
    output of the functions gets redirected to /dev/null, which is bad.
    
    % alias -g DN='>/dev/null'
    % run-help-foo () { echo bar; }
    % foo <ESC h>
    foo not found
    bar
    % foo DN<ESC h>
    foo not found
    %

diff --git a/Functions/Misc/run-help b/Functions/Misc/run-help
index f8aef0d..d0c3efe 100644
--- a/Functions/Misc/run-help
+++ b/Functions/Misc/run-help
@@ -101,7 +101,7 @@ do
 		do
 		    shift cmd_args
 		done
-		eval "run-help-$1:t ${(q@)cmd_args[2,-1]}"
+		eval "run-help-$1:t ${(qq@)cmd_args[2,-1]}"
 	    else
 		man $@:t
 	    fi

Bye, Jörg
-- 
Stasi 2.0 – http://www.dataloo.de/stasi-20-525.html


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to prevent alias expansion
  2009-01-04 15:57 How to prevent alias expansion Jörg Sommer
@ 2009-01-04 18:33 ` Bart Schaefer
  2009-01-04 21:51   ` Jörg Sommer
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2009-01-04 18:33 UTC (permalink / raw)
  To: zsh-workers

On Jan 4,  3:57pm, Jorg wrote: }
} 
} I've a problem with alias expansion. When using run-help and an global
} alias for redirect to /dev/null the command fails.
}
} % alias -g DN='>/dev/null'
} % git show DN<ESC h>
} <empty output>
} 
} I propose this patch:
} -		eval "run-help-$1:t ${(q@)cmd_args[2,-1]}"
} +		eval "run-help-$1:t ${(qq@)cmd_args[2,-1]}"

Hrm.  (qq) is not "quote twice", it's "quote with single quotes", whereas
(q) is "quote with backslashes".

So what's happening here is that quoting with backslashes doesn't change
"DN" at all (because it contains no metacharacters), so then during the
eval, global alias expansion kicks in as usual.  Quoting with single
quotes prevents alias expansion and passes (show DN) to run-help-git.

I can't decide what's correct here.  Are there are cases where someone
would want such an alias to expand?  run-help itself already looks up
aliases on the command word by way of "which".  Consequently a more
obvious patch (to a reader of the script) might be:

  emulate -R zsh
- setopt localoptions
+ setopt localoptions noaliases



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How to prevent alias expansion
  2009-01-04 18:33 ` Bart Schaefer
@ 2009-01-04 21:51   ` Jörg Sommer
  0 siblings, 0 replies; 3+ messages in thread
From: Jörg Sommer @ 2009-01-04 21:51 UTC (permalink / raw)
  To: zsh-workers

Hi Bart,

Bart Schaefer <schaefer@brasslantern.com> wrote:
> I can't decide what's correct here.  Are there are cases where someone
> would want such an alias to expand?

I would say no. I can't imagine which cases this should be. But this
doesn't mean they don't exist. :)

> run-help itself already looks up aliases on the command word by way of
> "which".  Consequently a more obvious patch (to a reader of the script)
> might be:
>
>   emulate -R zsh
> - setopt localoptions
> + setopt localoptions noaliases

Okay, let's do it.

Bye, Jörg.
-- 
Ich halte ihn zwar für einen Schurken und das was er sagt für
falsch – aber ich bin bereit mein Leben dafür einzusetzen, daß
er seine Meinung sagen kann.		(Voletair)


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-01-04 21:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-04 15:57 How to prevent alias expansion Jörg Sommer
2009-01-04 18:33 ` Bart Schaefer
2009-01-04 21:51   ` 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).