Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support aliases in completion scripts #827

Open
toast-gear opened this issue Nov 28, 2021 · 3 comments
Open

Support aliases in completion scripts #827

toast-gear opened this issue Nov 28, 2021 · 3 comments
Labels

Comments

@toast-gear
Copy link

toast-gear commented Nov 28, 2021

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.

@irgeek
Copy link

irgeek commented Nov 30, 2021

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.

@toast-gear
Copy link
Author

toast-gear commented Dec 3, 2021

@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 toast-gear changed the title How to get the bash completion script to work with aliases? Support aliases in completion scripts Dec 3, 2021
@stale
Copy link

stale bot commented Jun 12, 2022

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 stale bot added the stale label Jun 12, 2022
@stale stale bot removed the stale label Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants