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

Re: completion of normal commands after --



Phil Pennock wrote on Tue, Jan 03, 2023 at 19:23:59 -0500:
> So you might run:
> % aws-vault exec profile-foo -n my-command its-flags-and-args
> 
> I have it _almost_ working.  I can see it taking parameters for
> aws-vault after the profile name, I can see it switching to _normal
> execution and tab-completing commands from the path.  The problem comes
> with losing tab-completion for my-command's options.
> 
> Eg, I should be able to run:
> % aws-vault exec website -- ls -<TAB>
> and see the tab-completion for the ls(1) command.
> 
> Instead, at present, I can tab-complete the first word after the '--'
> and no further.  (Without the --, it tab-completes aws-vault's options,
> which is unfortunately correct: they'll be stolen).

That's exactly how «svnadmin freeze» works, and its completion handles
this correctly in a similar case, so see if you can crib from it:
<https://github.com/zsh-users/zsh/blob/d23bcf11714063498a9aec17a360af485026fef2/Completion/Unix/Command/_subversion#L317-L334>.

The two test cases in comments there work for me under `zsh -f` in 5.9.
A third case, with the words (-- .) swapped, offers «`arguments' or
`file'», rather than the external command's options.

Cheers,

Daniel

>     (exec)
>       _arguments -s -S -C \
>         '(-d --duration)'{-d,--duration=}'[duration of temporary or assume-role session]:duration' \
>         '(-n --no-session)'{-n,--no-session}'[use master credentials, no STS session]' \
>         '(-t --mfa-token)'{-t,--mfa-token=}'[the MFA token to use]: ' \
>         '(-j --json)'{-j,--json}'[be an AWS credential helper]' \
>         '(-s --server --ec2-server --ecs-server)'{-s,--server,--ec2-server}'[run EC2 metadata server in background for credentials]' \
>         '(-s --server --ec2-server --ecs-server)--ecs-server[run ECS credential server in background for credentials]' \
>         '--region=[the AWS region]:region:_aws_regions' \
>         '--lazy[When using --ecs-server, lazily fetch credentials]' \
>         '--stdout[Print the SSO link to the terminal without automatically opening the browser]' \
>         '1:profile name:_aws_profiles' \
>         '2:: :->wrapped-command' && return
> 
>       case "$state" in
>       (wrapped-command | '') # '' for the '--' scenario
>         shift $CURRENT words
>         CURRENT=1
>         _normal -p $service
>         ;;
>       esac
>       ;;
> 
> Guidance appreciated, and thanks in advance,
> -Phil
> 




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