4

I'm attempting to write a completion function for a custom wrapper around SSH called myssh. myssh takes command line arguments in either of the following forms:

myssh [myssh options] [ssh args]

or

myssh [myssh options] -- [ssh options] [ssh args]

How can I provide completion for myssh-specific options while reusing existing completion for ssh?

edit: I'd also like to use the _gnu_generic function mentioned here for completing myssh options.

1
  • 1
    For people who don’t have myssh options, they can simply compdef myssh=ssh. Hope this helps future visitors from Google. Oct 8, 2020 at 23:38

1 Answer 1

0

In a more general case where @Franklin\ Yu's comment does not suffice you can make a corresponding completion command. Take for example the flux command. This command, and many like it, is rather picky and expects its first parameter to the completion command to be the original command's name, so this fails:

$ compdef myflux=flux
$ myflux<tab>
l2advertisement.yaml  pool.yaml # <--- not expected

Introducing a helper command which replaces the first myflux in the $words variable fixes this:

_myflux() {
  words="flux ${words[@]:1}"     # replace myflux with flux, in `words` array
  _flux                           # call original completion command which expects a words array beginning with `flux`
}

$ compdef _myflux myflux

$ myflux<tab> 
bootstrap   -- Deploy Flux on a cluster the GitOps way.
build       -- Build a flux resource
check ...
...
# the above *is* expected.

Sometimes you are wrapping an original command with subcommands, like flux get source

The line with the mutation of the $words array would then become:

  words="flux get source ${words[@]:1}"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .