Currently if a developer works on a snap called foo
that ships an app called bar
, and they want that app to have tab completion in bash, they need to ship a completion snippet for the foo.bar
app. This works²⋅³⁰⁺ no matter what aliases are in play, but does force the developer to tweak their completion snippet — most non-snap apps aren’t called things like foo.bar
.
The completion snippet will have a line tying the command to whatever completion method is needed, something that starts with the command complete
and ends in the command being completed, for example
complete -W 'won too tri for' bar
they’d need to change it to
complete -W 'won too tri for' foo.bar
or, if they want to support both snap and non-snap installs with the same snippet,
complete -W 'won too tri for' bar foo.bar
or even
if [ "$SNAP" ]; then
complete -W 'won too tri for' foo.bar
else
complete -W 'won too tri for' bar
fi
I thought that the above was a reasonable compromise between things being magic and things working the way people expect (and people I talked with about this, in the abstract, agreed). However, I might’ve been wrong.
How do we make it better? Should we?
While we could parse the completion snippet to rewrite it to what the in-snap completer needs, doing so in the general case means essentially parsing bash scripts and tweaking the resulting ast. Even bash doesn’t parse bash scripts properly, so I don’t think doing it the magic way is sane.
One thing the developer could do is ship the regular snippet (that talks about bar
), but point the completer
key to a wrapper snippet that sourced the original and then added the appropriate complete
line. This requires no work on snappy’s part, and is relatively straightforward (and separate):
source the-real-completer
complete ... foo.bar
A mixed approach might be to add an additional key to the yaml (on IRC, lundmar
suggested completer-alias
). Then the current rewriting of the commandline into the snippet happens, but instead of towards foo.bar
, towards whatever that key points (defaulting to foo.bar
). Alternatively snapcraft could use that key to auto-create a snippet wrapper as above.
WTYT?