zsh-workers
 help / color / mirror / code / Atom feed
* [PATCH] Allow '=' aliases to be used with -L
@ 2018-03-22  1:19 Joey Pabalinas
  2018-03-22  1:37 ` Bart Schaefer
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Joey Pabalinas @ 2018-03-22  1:19 UTC (permalink / raw)
  To: zsh-workers; +Cc: Joey Pabalinas

[-- Attachment #1: Type: text/plain, Size: 985 bytes --]

Special case '=' aliases so that they can be output correctly
by -L and be used in startup scripts.

Signed-off-by: Joey Pabalinas <joeypabalinas@gmail.com>

 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/Src/hashtable.c b/Src/hashtable.c
index b7baa314220509240d..62f8e9df3b99b6d5e2 100644
--- a/Src/hashtable.c
+++ b/Src/hashtable.c
@@ -1303,11 +1303,17 @@ printaliasnode(HashNode hn, int printflags)
     }
 
     if (printflags & PRINT_LIST) {
-	/* Fast fail on unrepresentable values. */
+	/*
+	 * '=' aliases need to be special
+	 * cased with direct alias table
+	 * assignment (`aliases[=]=...`).
+	 */
 	if (strchr(a->node.nam, '=')) {
-	    zwarn("invalid alias '%s' encountered while printing aliases", 
-		  a->node.nam);
-	    /* ### TODO: Return an error status to the C caller */
+	    printf("aliases[=]");
+	    putchar('=');
+	    quotedzputs(a->text, stdout);
+
+	    putchar('\n');
 	    return;
 	}
 
-- 
2.16.2

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

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

* Re: [PATCH] Allow '=' aliases to be used with -L
  2018-03-22  1:19 [PATCH] Allow '=' aliases to be used with -L Joey Pabalinas
@ 2018-03-22  1:37 ` Bart Schaefer
  2018-03-22  2:58   ` Joey Pabalinas
  2018-03-23 10:09 ` Nikolay Aleksandrovich Pavlov (ZyX)
  2018-03-23 17:29 ` Stephane Chazelas
  2 siblings, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2018-03-22  1:37 UTC (permalink / raw)
  To: Joey Pabalinas; +Cc: zsh-workers

On Wed, Mar 21, 2018 at 6:19 PM, Joey Pabalinas <joeypabalinas@gmail.com> wrote:
> Special case '=' aliases so that they can be output correctly
> by -L and be used in startup scripts.

Unfortunately you can't put this in the base shell, because assignment
to the aliases array is only supported by a module.

% zmodload -up aliases
% aliases[x]=foo
zsh: aliases: assignment to invalid subscript range


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

* Re: [PATCH] Allow '=' aliases to be used with -L
  2018-03-22  1:37 ` Bart Schaefer
@ 2018-03-22  2:58   ` Joey Pabalinas
  2018-03-22  3:08     ` Bart Schaefer
  2018-03-23  6:32     ` Daniel Shahaf
  0 siblings, 2 replies; 11+ messages in thread
From: Joey Pabalinas @ 2018-03-22  2:58 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Joey Pabalinas, zsh-workers

[-- Attachment #1: Type: text/plain, Size: 1516 bytes --]

On Wed, Mar 21, 2018 at 06:37:37PM -0700, Bart Schaefer wrote:
> Unfortunately you can't put this in the base shell, because assignment
> to the aliases array is only supported by a module.

Ah you are right, I didn't realize that. How about if we check if the
module is loaded first? If it happens to not be we can just use the
old failure path.

Revised patch below:

 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/Src/hashtable.c b/Src/hashtable.c
index b7baa314220509240d..53e7e99e1a9f1505b6 100644
--- a/Src/hashtable.c
+++ b/Src/hashtable.c
@@ -1303,11 +1303,23 @@ printaliasnode(HashNode hn, int printflags)
     }
 
     if (printflags & PRINT_LIST) {
-	/* Fast fail on unrepresentable values. */
+	/*
+	 * '=' aliases need to be special cased with direct alias
+	 * table assignment (`aliases[=]=...`). If the zsh/parameter
+	 * module isn't loaded just print a warning and fail.
+	 */
 	if (strchr(a->node.nam, '=')) {
-	    zwarn("invalid alias '%s' encountered while printing aliases", 
-		  a->node.nam);
-	    /* ### TODO: Return an error status to the C caller */
+	    /* Fast fail on unrepresentable values. */
+	    if (!module_loaded("zsh/parameter")) {
+		zwarn("invalid alias '%s' encountered while printing aliases",
+		 a->node.nam);
+		/* ### TODO: Return an error status to the C caller */
+		return;
+	    }
+
+	    printf("aliases[=]=");
+	    quotedzputs(a->text, stdout);
+	    putchar('\n');
 	    return;
 	}
 
-- 
2.16.2

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

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

* Re: [PATCH] Allow '=' aliases to be used with -L
  2018-03-22  2:58   ` Joey Pabalinas
@ 2018-03-22  3:08     ` Bart Schaefer
  2018-03-22  3:12       ` Joey Pabalinas
  2018-03-23  6:32     ` Daniel Shahaf
  1 sibling, 1 reply; 11+ messages in thread
From: Bart Schaefer @ 2018-03-22  3:08 UTC (permalink / raw)
  To: Joey Pabalinas; +Cc: zsh-workers

On Wed, Mar 21, 2018 at 7:58 PM, Joey Pabalinas <joeypabalinas@gmail.com> wrote:
>
> Ah you are right, I didn't realize that. How about if we check if the
> module is loaded first?

The module being loaded when "alias -L" is executed doesn't mean it
will be when the assignment happens, and because of autoloads finding
that the module is not loaded does not tell you whether the assignment
will later succeed.

Also there are no other similar dependencies of the core on the
success of module_loaded().


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

* Re: [PATCH] Allow '=' aliases to be used with -L
  2018-03-22  3:08     ` Bart Schaefer
@ 2018-03-22  3:12       ` Joey Pabalinas
  0 siblings, 0 replies; 11+ messages in thread
From: Joey Pabalinas @ 2018-03-22  3:12 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Joey Pabalinas, zsh-workers

[-- Attachment #1: Type: text/plain, Size: 305 bytes --]

On Wed, Mar 21, 2018 at 08:08:37PM -0700, Bart Schaefer wrote:
> Also there are no other similar dependencies of the core on the
> success of module_loaded().

Oh wow yeah, that definitely makes this a bad idea then. No worries, at
least I learned something today :)

-- 
Cheers,
Joey Pabalinas

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

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

* Re: [PATCH] Allow '=' aliases to be used with -L
  2018-03-22  2:58   ` Joey Pabalinas
  2018-03-22  3:08     ` Bart Schaefer
@ 2018-03-23  6:32     ` Daniel Shahaf
  2018-03-23  7:39       ` Joey Pabalinas
  1 sibling, 1 reply; 11+ messages in thread
From: Daniel Shahaf @ 2018-03-23  6:32 UTC (permalink / raw)
  To: Joey Pabalinas; +Cc: zsh-workers

Joey Pabalinas wrote on Wed, Mar 21, 2018 at 16:58:07 -1000:
> +++ b/Src/hashtable.c
> @@ -1303,11 +1303,23 @@ printaliasnode(HashNode hn, int printflags)
>  	if (strchr(a->node.nam, '=')) {
> +	    printf("aliases[=]=");

For future reference, a->node.nam could also have been "foo=bar", which
is not a useful value (assignments have precedence over aliases) but would
be misserialized by the patch as written.

Cheers,

Daniel


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

* Re: [PATCH] Allow '=' aliases to be used with -L
  2018-03-23  6:32     ` Daniel Shahaf
@ 2018-03-23  7:39       ` Joey Pabalinas
  0 siblings, 0 replies; 11+ messages in thread
From: Joey Pabalinas @ 2018-03-23  7:39 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: Joey Pabalinas, zsh-workers

[-- Attachment #1: Type: text/plain, Size: 363 bytes --]

On Fri, Mar 23, 2018 at 06:32:58AM +0000, Daniel Shahaf wrote:
> For future reference, a->node.nam could also have been "foo=bar", which
> is not a useful value (assignments have precedence over aliases) but would
> be misserialized by the patch as written.

Aha, I had completely overlooked that case! Good to note, thanks.

-- 
Cheers,
Joey Pabalinas

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

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

* Re: [PATCH] Allow '=' aliases to be used with -L
  2018-03-22  1:19 [PATCH] Allow '=' aliases to be used with -L Joey Pabalinas
  2018-03-22  1:37 ` Bart Schaefer
@ 2018-03-23 10:09 ` Nikolay Aleksandrovich Pavlov (ZyX)
  2018-03-23 10:36   ` Joey Pabalinas
  2018-03-23 17:29 ` Stephane Chazelas
  2 siblings, 1 reply; 11+ messages in thread
From: Nikolay Aleksandrovich Pavlov (ZyX) @ 2018-03-23 10:09 UTC (permalink / raw)
  To: Joey Pabalinas, zsh-workers



22.03.2018, 04:19, "Joey Pabalinas" <joeypabalinas@gmail.com>:
> Special case '=' aliases so that they can be output correctly
> by -L and be used in startup scripts.
>
> Signed-off-by: Joey Pabalinas <joeypabalinas@gmail.com>
>
>  1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/Src/hashtable.c b/Src/hashtable.c
> index b7baa314220509240d..62f8e9df3b99b6d5e2 100644
> --- a/Src/hashtable.c
> +++ b/Src/hashtable.c
> @@ -1303,11 +1303,17 @@ printaliasnode(HashNode hn, int printflags)
>      }
>
>      if (printflags & PRINT_LIST) {
> - /* Fast fail on unrepresentable values. */
> + /*
> + * '=' aliases need to be special
> + * cased with direct alias table
> + * assignment (`aliases[=]=...`).
> + */
>          if (strchr(a->node.nam, '=')) {
> - zwarn("invalid alias '%s' encountered while printing aliases",
> - a->node.nam);
> - /* ### TODO: Return an error status to the C caller */
> + printf("aliases[=]");

This looks like all aliases having `=` in them will be printed with exactly the same key `=`, including those which are not equal to `=`.

> + putchar('=');
> + quotedzputs(a->text, stdout);
> +
> + putchar('\n');
>              return;
>          }
>
> --
> 2.16.2


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

* Re: [PATCH] Allow '=' aliases to be used with -L
  2018-03-23 10:09 ` Nikolay Aleksandrovich Pavlov (ZyX)
@ 2018-03-23 10:36   ` Joey Pabalinas
  0 siblings, 0 replies; 11+ messages in thread
From: Joey Pabalinas @ 2018-03-23 10:36 UTC (permalink / raw)
  To: Nikolay Aleksandrovich Pavlov (ZyX); +Cc: Joey Pabalinas, zsh-workers

[-- Attachment #1: Type: text/plain, Size: 390 bytes --]

On Fri, Mar 23, 2018 at 01:09:10PM +0300, Nikolay Aleksandrovich Pavlov (ZyX) wrote:
> This looks like all aliases having `=` in them will be printed with exactly
> the same key `=`, including those which are not equal to `=`.

Right, I didn't think about the case where people create aliases aside
from plain 'ol "=".

Live and learn as they say :)

-- 
Cheers,
Joey Pabalinas

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

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

* Re: [PATCH] Allow '=' aliases to be used with -L
  2018-03-22  1:19 [PATCH] Allow '=' aliases to be used with -L Joey Pabalinas
  2018-03-22  1:37 ` Bart Schaefer
  2018-03-23 10:09 ` Nikolay Aleksandrovich Pavlov (ZyX)
@ 2018-03-23 17:29 ` Stephane Chazelas
  2018-03-24  0:02   ` Bart Schaefer
  2 siblings, 1 reply; 11+ messages in thread
From: Stephane Chazelas @ 2018-03-23 17:29 UTC (permalink / raw)
  To: Joey Pabalinas; +Cc: zsh-workers

2018-03-21 15:19:05 -1000, Joey Pabalinas:
> Special case '=' aliases so that they can be output correctly
> by -L and be used in startup scripts.
[...]

FWIW, another corner case:

$ aliases[(e)]=whatever
$ alias -L
alias ''=whatever
$ eval "$(alias -L)"
zsh: whatever not found

Actually, I didn't quite expect that error message, I would have thought

echo ''=foo

would be the same as

echo '=foo'

That the = operator would not be recognised in that  context.

I can't say I like that behaviour. It gets worse with expansions:

$ echo $0=ls
/bin/zsh=ls
$ echo $1=ls
/bin/ls

-- 
Stephane


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

* Re: [PATCH] Allow '=' aliases to be used with -L
  2018-03-23 17:29 ` Stephane Chazelas
@ 2018-03-24  0:02   ` Bart Schaefer
  0 siblings, 0 replies; 11+ messages in thread
From: Bart Schaefer @ 2018-03-24  0:02 UTC (permalink / raw)
  To: zsh-workers

On Mar 23,  5:29pm, Stephane Chazelas wrote:
}
} FWIW, another corner case:
} 
} $ aliases[(e)]=whatever

That's actually not relevant at all to what follows, except that it
creates the string for "eval".

} Actually, I didn't quite expect that error message, I would have thought
} 
} echo ''=foo
} 
} would be the same as
} 
} echo '=foo'

The problem here is that zsh lacks a representation for "quoted nothing".
The empty string gets removed entirely from the word rather than being
left behind to let the later parse know that something was there that
disappeared.

I can't think of an easy way to fix this without some significant lexing
changes, but perhaps someone else has an idea.


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

end of thread, other threads:[~2018-03-24  0:02 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-22  1:19 [PATCH] Allow '=' aliases to be used with -L Joey Pabalinas
2018-03-22  1:37 ` Bart Schaefer
2018-03-22  2:58   ` Joey Pabalinas
2018-03-22  3:08     ` Bart Schaefer
2018-03-22  3:12       ` Joey Pabalinas
2018-03-23  6:32     ` Daniel Shahaf
2018-03-23  7:39       ` Joey Pabalinas
2018-03-23 10:09 ` Nikolay Aleksandrovich Pavlov (ZyX)
2018-03-23 10:36   ` Joey Pabalinas
2018-03-23 17:29 ` Stephane Chazelas
2018-03-24  0:02   ` Bart Schaefer

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).