aws-vault icon indicating copy to clipboard operation
aws-vault copied to clipboard

Support aliases in completion scripts

Open toast-gear opened this issue 3 years ago • 3 comments

aws-vault exec $profile is quite long and covers 90% of my usage of aws-vault once setup is complete, furthermore I need to unset variables to change the aws account I am assumed against making the process even more verbose. As a result of all this I like alias my primary aws-vault command to something a bit smaller alias awsv='unset AWS_VAULT AWS_REGION AWS_DEFAULT_REGION; aws-vault exec'. Using my alias breaks the completion script however.

Using the normal aws-vault command tabbing will bring up the configured profiles, if I use my alias tabbing just brings up a ls of one of my completion script directories.

What do I need to add to my .bashrc to allow my alias to work with aws-vault? Perhaps this information should be included in the shell-completion section as I think aliasing the command will be a fairly common configuration.

https://kubernetes.io/docs/tasks/tools/included/optional-kubectl-configs-bash-linux/#enable-kubectl-autocompletion Kubernetes provides some information on how to get completion scripts to work with an alias, it would be great if aws-vault provided the same sort of documentation as this for those that like to use aliases.

toast-gear avatar Nov 28 '21 20:11 toast-gear

The simple fix for this is to create multiple aliases--one for each profile. Assuming you have two profile, work and home, for instance, you'd do something like this:

alias awsv-work ='env -u AWS_VAULT -u AWS_REGION -u AWS_DEFAULT_REGION aws-vault exec work'
alias awsv-home='env -u AWS_VAULT -u AWS_REGION -u AWS_DEFAULT_REGION aws-vault exec home'

Your shell should then auto-complete the alias names by default.

The alternative is to write your own shell completion script. It's doable, but not exactly trivial. By aliasing parts of the command, you're essentially changing the completion options so the script included with aws-vault likely won't work without significant modification.

irgeek avatar Nov 30 '21 23:11 irgeek

@irgeek I've got too many profiles to do the alias trick :(

Thanks for your input, it works as you said:

alias aws-vault='unset AWS_VAULT AWS_REGION AWS_DEFAULT_REGION; aws-vault      # works
alias aws-vault='unset AWS_VAULT AWS_REGION AWS_DEFAULT_REGION; aws-vault exec # doesn't work
alias awsv='unset AWS_VAULT AWS_REGION AWS_DEFAULT_REGION; aws-vault           # doesn't work
alias awsv='unset AWS_VAULT AWS_REGION AWS_DEFAULT_REGION; aws-vault exec      # doesn't work

I'm happy enough with this setup, perhaps it's worth tagging this issue an an enhancement though as adjusting the completion script to support aliases would be a great enhancement, e.g.:

alias awsv='unset AWS_VAULT AWS_REGION AWS_DEFAULT_REGION; aws-vault

toast-gear avatar Dec 03 '21 12:12 toast-gear

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jun 12 '22 18:06 stale[bot]