Skip to content

AutoComplete tips

Tristan Morgan edited this page Aug 5, 2021 · 8 revisions

Autocomplete that can be installed with:

$ complete -C /usr/local/bin/awskeyring awskeyring

To set your environment easily the following bash function helps:

awsenv() { eval "$(awskeyring env $@)"; }

And if you want autocompletion for the environment function try the following:

_awsenv_comp() {
  COMPREPLY=( $(compgen -W "$(awskeyring list) --no-token --unset" -- "${COMP_WORDS[COMP_CWORD]}" ))
}
complete -F _awsenv_comp awsenv

Related to autocomplete is autocorrection. If you have Thor 0.20.3 with did_you_mean 1.0.3 installed and you make a typo you will get a helpful suggestion as to what should have been typed.

$ awskeyring halp
Could not find command "halp".
Did you mean?  "help"

Also the short forms of commands won't appear in the suggestions for autocomplete but the options and help messages will work for them. (-v, init, adr, con, ls, lsr, rm, rmr, rmt, rot, tok, up)

$ awskeyring help rmr
Usage:
  awskeyring remove-role ROLE

Removes a ROLE from the keyring

Finally, Awskeyring will also search for matching prefixes for commands, accounts and roles. If the prefix supplied on the command line matches only one then it will be considered valid.

$ awskeyring he he he
Usage:
  awskeyring help [COMMAND]

Describe available commands or one specific command
Clone this wiki locally