* Re: Alias named '=' [not found] ` <20171008183756.h45qeeqqbn2wthh3@tarpaulin.shahaf.local2> @ 2017-10-09 14:49 ` Peter Stephenson 2017-10-09 15:04 ` Daniel Shahaf 0 siblings, 1 reply; 6+ messages in thread From: Peter Stephenson @ 2017-10-09 14:49 UTC (permalink / raw) To: Zsh Hackers' List Should we say something like this, or is it simply adding more words for people to say they can't be bothered to read it? pws diff --git a/Doc/Zsh/grammar.yo b/Doc/Zsh/grammar.yo index 463ac88..c77a9a8 100644 --- a/Doc/Zsh/grammar.yo +++ b/Doc/Zsh/grammar.yo @@ -568,6 +568,16 @@ itemiz(With global aliasing, any command separator, any redirection operator, and `tt(LPAR())' or `tt(RPAR())' when not part of a glob pattern) enditemize() +Anything not listed is em(not) a word and no attempt is made to expand +it as an alias, however it is defined (i.e. via the builtin or +the special parameter tt(aliases) described in +ifnzman(noderef(The zsh/parameter Module))\ +ifzman(the section THE ZSH/PARAMETER MODULE in zmanref(zshmodules))). +For example, an expression containing an tt(=) at the start of +a command line is always an assignment and cannot be expanded as an alias. +However, the shell does not attempt to deduce whether the string +corresponds to a word at the time the alias is created. + It is not presently possible to alias the `tt(LPAR()LPAR())' token that introduces arithmetic expressions, because until a full statement has been parsed, it cannot be distinguished from two consecutive `tt(LPAR())' ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Alias named '=' 2017-10-09 14:49 ` Alias named '=' Peter Stephenson @ 2017-10-09 15:04 ` Daniel Shahaf 2017-10-09 15:20 ` Peter Stephenson 0 siblings, 1 reply; 6+ messages in thread From: Daniel Shahaf @ 2017-10-09 15:04 UTC (permalink / raw) To: zsh-workers Peter Stephenson wrote on Mon, 09 Oct 2017 15:49 +0100: > Should we say something like this, or is it simply adding more words for > people to say they can't be bothered to read it? > I think this section should describe the common, and less-common-but-still-sane, use-cases before it discusses corner cases such as aliasing «((», «&&», and «x=y». So, the content (existing and new) is good, but let's move it to a "dangerous bend" section, like the "Rules" section for documenting parameter substitution rules. Makes sense? Cheers, Daniel (is there a "dangerous bend" Unicode character?) ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Alias named '=' 2017-10-09 15:04 ` Daniel Shahaf @ 2017-10-09 15:20 ` Peter Stephenson 2017-10-09 15:30 ` Bart Schaefer 0 siblings, 1 reply; 6+ messages in thread From: Peter Stephenson @ 2017-10-09 15:20 UTC (permalink / raw) To: zsh-workers On Mon, 09 Oct 2017 15:04:47 +0000 Daniel Shahaf <d.s@daniel.shahaf.name> wrote: > Peter Stephenson wrote on Mon, 09 Oct 2017 15:49 +0100: > > Should we say something like this, or is it simply adding more words for > > people to say they can't be bothered to read it? > > > > I think this section should describe the common, and > less-common-but-still-sane, use-cases before it discusses corner cases > such as aliasing «((», «&&», and «x=y». So we could do something like this? I moved down POSIX_ALIASES because it's part of basic function but not as basic as what an alias actually does. pw diff --git a/Doc/Zsh/grammar.yo b/Doc/Zsh/grammar.yo index 463ac88..4f219c5 100644 --- a/Doc/Zsh/grammar.yo +++ b/Doc/Zsh/grammar.yo @@ -568,15 +568,6 @@ itemiz(With global aliasing, any command separator, any redirection operator, and `tt(LPAR())' or `tt(RPAR())' when not part of a glob pattern) enditemize() -It is not presently possible to alias the `tt(LPAR()LPAR())' token that -introduces arithmetic expressions, because until a full statement has been -parsed, it cannot be distinguished from two consecutive `tt(LPAR())' -tokens introducing nested subshells. - -When tt(POSIX_ALIASES) is set, only plain unquoted strings are eligible -for aliasing. The tt(alias) builtin does not reject ineligible aliases, -but they are not expanded. - Alias expansion is done on the shell input before any other expansion except history expansion. Therefore, if an alias is defined for the word tt(foo), alias expansion may be avoided by quoting part of the @@ -586,11 +577,36 @@ tt(\foo) as well. Also, if a separator such as tt(&&) is aliased, tt(\&&) turns into the two tokens tt(\&) and tt(&), each of which may have been aliased separately. Similarly for tt(\<<), tt(\>|), etc. +When tt(POSIX_ALIASES) is set, only plain unquoted strings are eligible +for aliasing. The tt(alias) builtin does not reject ineligible aliases, +but they are not expanded. + For use with completion, which would remove an initial backslash followed by a character that isn't special, it may be more convenient to quote the word by starting with a single quote, i.e. tt('foo); completion will automatically add the trailing single quote. +subsect(Alias difficulties) + +Although aliases can be used in ways that bend normal shell sytnax, not +every string of non-white-space characters can be used as an alias. + +Any set of characters not listed as a word above is not a word, hence no +attempt is made to expand it as an alias, no matter how it is defined +(i.e. via the builtin or the special parameter tt(aliases) described in +ifnzman(noderef(The zsh/parameter Module))\ +ifzman(the section THE ZSH/PARAMETER MODULE in zmanref(zshmodules))). +For example, an expression containing an tt(=) at the start of +a command line is always an assignment and cannot be expanded as an alias. +However, as noted in the case of tt(POSIX_ALIASES) above, the shell does +not attempt to deduce whether the string corresponds to a word at the +time the alias is created. + +It is not presently possible to alias the `tt(LPAR()LPAR())' token that +introduces arithmetic expressions, because until a full statement has been +parsed, it cannot be distinguished from two consecutive `tt(LPAR())' +tokens introducing nested subshells. + There is a commonly encountered problem with aliases illustrated by the following code: ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Alias named '=' 2017-10-09 15:20 ` Peter Stephenson @ 2017-10-09 15:30 ` Bart Schaefer 2017-10-09 15:35 ` Daniel Shahaf 0 siblings, 1 reply; 6+ messages in thread From: Bart Schaefer @ 2017-10-09 15:30 UTC (permalink / raw) To: zsh-workers On Oct 9, 4:20pm, Peter Stephenson wrote: } Subject: Re: Alias named '=' } } On Mon, 09 Oct 2017 15:04:47 +0000 } Daniel Shahaf <d.s@daniel.shahaf.name> wrote: } > Peter Stephenson wrote on Mon, 09 Oct 2017 15:49 +0100: } > > Should we say something like this, or is it simply adding more words for } > > people to say they can't be bothered to read it? } > } > I think this section should describe the common, and } > less-common-but-still-sane, use-cases before it discusses corner cases } > such as aliasing "((", "&&", and "x=y". } } So we could do something like this? This doesn't describe what the question/discussion was about, does it? torch% aliases[=]='echo equal' torch% = equal The text you've written isn't wrong about assignment interpretation, but it implies that the above would not work. The problem with the above is that the alias *builtin* can't deal with it, not that it's a problem in command position. Also I'm abivalent about moving the text about about the "((" token as that is closely related to the dicussion about global aliasing of other operator-like tokens. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Alias named '=' 2017-10-09 15:30 ` Bart Schaefer @ 2017-10-09 15:35 ` Daniel Shahaf 2017-10-10 9:02 ` Peter Stephenson 0 siblings, 1 reply; 6+ messages in thread From: Daniel Shahaf @ 2017-10-09 15:35 UTC (permalink / raw) To: zsh-workers Bart Schaefer wrote on Mon, 09 Oct 2017 08:30 -0700: > Also I'm abivalent about moving the text about about the "((" token as > that is closely related to the dicussion about global aliasing of other > operator-like tokens. I, on the other hand, like the new text but wondered whether the discussion the inability to \-escape a «&&» alias belongs further down. Aliasing tokens isn't a common or usual thing to do. Perhaps the discussion about \&& could move to where the discussion about (( is now. ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: Alias named '=' 2017-10-09 15:35 ` Daniel Shahaf @ 2017-10-10 9:02 ` Peter Stephenson 0 siblings, 0 replies; 6+ messages in thread From: Peter Stephenson @ 2017-10-10 9:02 UTC (permalink / raw) To: zsh-workers I've committed an update to the documentation, you can fight over further changes. pws ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-10-10 9:11 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <6e3f43ea-45b0-d6a8-43b9-18845ea4edc9@necoro.eu> [not found] ` <m360bqt54h.fsf@luffy.cx> [not found] ` <7d8ab2fa-3130-1e43-8807-f94025fd62ed@necoro.eu> [not found] ` <CGME20171008183934epcas3p470fe7672a1689fa0e84d328d2ffaf2b1@epcas3p4.samsung.com> [not found] ` <20171008183756.h45qeeqqbn2wthh3@tarpaulin.shahaf.local2> 2017-10-09 14:49 ` Alias named '=' Peter Stephenson 2017-10-09 15:04 ` Daniel Shahaf 2017-10-09 15:20 ` Peter Stephenson 2017-10-09 15:30 ` Bart Schaefer 2017-10-09 15:35 ` Daniel Shahaf 2017-10-10 9:02 ` Peter Stephenson
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).