Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: alias hygiene
- X-seq: zsh-users 23134
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: alias hygiene
- Date: Sat, 17 Feb 2018 13:54:36 +0000
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=eit90v wfRPmb9e5L4lePcZDrlcz8sGwlTwNLGteKHqE=; b=bzd46kXyY/jauDC3/M/fUA 4lHtC+K1L+38JtvHRsskRLj0qZ7tJo4daxomKkpunEvanC4mvvNMIcdVFYoZl6LJ H23Yv992rYmxCKErMXB2tlyQbkyBID0OIQr9GGngdctEMPTfgw0HwTKUf9FKs8sv AHEZt4LUfDWYX846q8xMDY1xrwWHVzQSNlfEgyqIv11Nv120D678WPwOVeA3ZXLK yvO49EQ0ipGtE2QN7MxR7fKe4rNUhZK/Rkojmcn9ggUsQyYAAuElwy/Zri+E+OZz DN+SSsQEe52AH3Gqu1XCtssaK2uw0FdcTy3nCpaQY3flmR2fePoAI/8LG/sL/Ozg ==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=eit90v wfRPmb9e5L4lePcZDrlcz8sGwlTwNLGteKHqE=; b=lo/gM5g41gt+cc8EfqlE9L qqvaxGeyf9crVEIYEEZIYpkNtBe93LLkeutBLVZGpLat9sGgsGmpfTQW+bbTo98T i8xUan5jf6My8l0RJArclBpJaWQ/JLh2Ro3/H4MqSvlsZWFA3WYHHLKCr0bXfpc9 SnITz0UV/1Bmh/1tkOnKJvdIRL1e+9HbEjrC7CIImU+9/qp8EtghV7UNMJcd5o7X YnK3FCpEFZ9uB7ltnBLo99GQeV+e1T0NGztJlxALBwMjiEJYA6shvEq8i0SHtaqr 8SqrCiPrXNqQtibVVOF9ZIf3jAcZbKYEZ4U124uLrRoZrhKxraqi7AoKixnpjTKw ==
- In-reply-to: <37bb7b6b-ad70-6d03-f979-0e0d3b0be4d3@eastlink.ca>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- List-unsubscribe: <mailto:zsh-users-unsubscribe@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <1679a1e0-f716-e501-c4c2-f7e485f9701f@eastlink.ca> <1518827410.2159479.1273706656.1F5B436D@webmail.messagingengine.com> <37bb7b6b-ad70-6d03-f979-0e0d3b0be4d3@eastlink.ca>
Ray Andrews wrote on Fri, 16 Feb 2018 19:14 -0800:
> On 16/02/18 04:30 PM, Daniel Shahaf wrote:
> >
> > I don't understand your question, but allow me to review this code _without_
> > knowing its context or purpose:
> Thanks Daniel, I did suspect it would not be kosher. Is there some way
> to see how this looks to the parser after expansion? That way I'd
> probably be able to understand the issue better.
You could use a widget such as:
[[[
f() {
local arg
for arg in ${(z)1}; do
print -r -l -- «${(Q)arg}»
done
}
show-buffer-parse() {
zle -M "$(f "$PREBUFFER$LBUFFER")"
}
zle -N show-buffer-parse
bindkey '^T' show-buffer-parse
]]]
There may be plugins that could help, too.
> >
> > 0. It's a syntax error.
> >
> > 1. Calling the alias «_grep» clashes with compsys's function of that name.
> Ah! So I could just rename it as far as that goes? It does seem to
> work fine, but this sounds like a gotcha.
Yes, just rename it.
> > 2. Aliases don't have positional parameters. That «$1» is syntactically valid
> > but I am not sure whether it does what you want (or, rather, whether it would
> > do what you want after you fix #4).
> Actually that's the reason for the alias, I want it to pick up the
> parameters inline after the alias is expanded.
That does not require using $1:
% alias x='echo foo'
% x qux
However, note also:
% alias x='echo foo; echo bar'
% x qux
If you wanted that to print «foo qux», you would have had to use a function.
The use of $1 in your excerpt is a latent bug.
> It does what I want but
> I question its safety. In practical terms the
> "^|$string|$second_string" construction is not something I want to try
> passing to a function
You really, really have to learn quoting and escaping. There is no problem at
all with strings that contain variable substitutions and shell and extendedglob
metacharacters, provided that they are quoted.
I refer you again to the second point #4 in my previous email. Without running
that command, what do you expect it to output? Now run it. Do you understand
why it behaved as it did?
> so I thought to just leave it there for the
> expanded alias to eat, that is, for egrep to eat.
That pipe is not quoted, hence it is syntactical. Alias definitions are simple
command so they end at a command separator — which includes «;» and «&&» and
«|», among others.
> >
> > 3. Do not interpolate strings into command strings; that's a bobby tables bug.
> This is what I had expected the issue would be. Mind, I cobble strings
> together into command strings all the time and I've gotten used to the
> little tweaks needed. How can I read up on this 'bobby tables'? I
> might have developed some bad habits.
You might do a web search for that term.
> > More information:
> >
> > 0. «||» is invalid at the start of a logical line. Either there is an error
> > message you did not tell us about or there is a difference between what you ran
> > and what you posted.
>
> Right, context again, I should only show what is strictly relevant to
> the question.
I was trying to point out that your report was either incomplete or inaccurate,
not that it had excessive detail.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author