Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] _gpg: Use explicit UIDs for public / secret keys.



Very weirdly, from some reason, when I tried to test both with `env` and
with `eval`, sometimes it worked and sometimes not, no idea why it
wasn't even consistent.

Therefor, after reading the documentation, I've created a better and
probably truly deterministic to do it. Here it is including the quoted
`words[1]` and `needed`:

    local public_keys=(${(@s.:.)${(f)"$(_call_program public-keys ${(q)words[1]} ${(q)needed} --list-public-keys --list-options no-show-photos --with-colons)"}})

I hope you'll find it better. I'm sending a final patch after this
message, tell me if there is anything more to improve.

On Thu, Jun 07, 2018 at 06:40:14AM +0000, Daniel Shahaf wrote:
> Doron Behar wrote on Tue, 05 Jun 2018 18:47 +0300:
> > On Sun, Jun 03, 2018 at 09:43:50PM +0000, Daniel Shahaf wrote:
> > > doron.behar@xxxxxxxxx wrote on Sat, Jun 02, 2018 at 18:26:51 +0300:
> > > > From: Doron Behar <doron.behar@xxxxxxxxx>
> > > > 
> > > > Use the `--with-colons` option and parse the output.
> > > > ---
> > > >  Completion/Unix/Command/_gpg | 69 ++++++++++++++++++++++++++++++++----
> > > >  1 file changed, 63 insertions(+), 6 deletions(-)
> > > > 
> > > > diff --git a/Completion/Unix/Command/_gpg b/Completion/Unix/Command/_gpg
> > > > index 48a36eff2..7e707c5f6 100644
> > > > --- a/Completion/Unix/Command/_gpg
> > > > +++ b/Completion/Unix/Command/_gpg
> > > > @@ -206,20 +206,77 @@ fi
> > > >  
> > > >  case "$state" in
> > > >    public-keys)
> > > > -    _wanted public-keys expl 'public key' \
> > > > -	compadd ${${(Mo)$(_call_program public-keys $words[1] $needed --list-public-keys --list-options no-show-photos):%<*>}//(<|>)/} && return
> > > > +    local public_keys=(${(@s.:.)$(_call_program public-keys eval IFS=$'\n' $words[1] $needed --list-public-keys --list-options no-show-photos --with-colons)})
> > > 
> > > This isn't quite right.
> > > 
> > > The first argument to «eval» here is the five bytes «IFS=\n» (where \n stands
> > > for an 0x0A byte), so the eval'd code sets IFS to the empty string, not to the
> > > one-byte string $'\n', and the assignment isn't specific to the command either.
> > > 
> > > I'm not sure what value you _meant_ to set IFS to.  If you meant to set it to a
> > > newline, you could do something like this:
> > > 
> > >     …$(_call_program public-keys eval IFS=${(q):-$'\n'} ${(q)words[1]} ${(q)needed} --list-public-keys --list-options no-show-photos --with-colons)…
> > > 
> > > I also added (q) to the other variable expansions.
> > 
> > Actually, I've mistakenly sent the patch with eval, I got confused with
> > `env` which was my original intention. Both using my original version
> > with `env` instead of `eval` and your version with the quoted IFS work,
> > what shall it be?
> 
> IFS should never be exported, so use eval please.
> 
> Please use double escaping, though (that is, ${(q)${(q)foo}}: that's needed since
> _call_program does an eval anyway, in addition to the one you spell out
> in _call_program's arguments.



Messages sorted by: Reverse Date, Date, Thread, Author