detect shell is fish in executable for auto-complete
synfinatic opened this issue · comments
fish, version 3.7.1
Darwin 23.4.0
TL;DR: I am the author of aws-sso-cli and I would like to add tab auto-completion for fish. I'm running into an issue due to how fish is different from bash and zsh regarding how it processes :
as an argument value.
Specifically, I'll have a command like aws-sso exec -p <profile name>
where <profile name>
is often in the format of <AWS Account Alias>:<AWS IAM Role Name>
. When I generate the list of possible values for -p
for bash or zsh, I must escape it to be like fooAccount\:barProfile
. But fish seems to require there to be no escaping of the semi-colon because it's not a word delim maybe?
If I use os.Getenv("FISH_VERSION") it evaluates to an empty string, because I believe it is not actually exported: #374
Or perhaps I'm just doing it wrong in my aws-sso.fish file?
Are there any options available to me?
When you generate a completion script from your tool, you would typically just pass the shell as an argument. E.g. pip wants
pip3 completion --fish
Now, when you generate the list of candidates, I would usually just print the candidates, and then handle the parsing of that in the shell, e.g. let the bash/zsh scripts escape what they need to have escaped. Print the simplest format you can and let the shell handle shell-specific concerns.
If you can't do that, you'd have to either unescape the argument in fish, e.g.
aws-sso exec -p <profile name> | string replace -ra '\\\:' ':'
or add a flag to indicate it shouldn't escape:
aws-sso exec -p <profile name> --no-escape-colons
(or call it --fish
, or set an exported variable like FISH_MODE=1 aws-sso
and check that)
Thanks. That works. That said, there doesn't seem to be any means of auto-detecting fish which is annoying. Means my users have to manually specify --shell=fish
to install the auto-complete file.