awslabs / aws-shell

An integrated shell for working with the AWS CLI.
Apache License 2.0
7.15k stars 769 forks source link

[Feature Request] Ability to define command aliases per-profiles. #234

Open ToMMy86 opened 4 years ago

ToMMy86 commented 4 years ago

Hello, i'm trying it out the aws-shell in my environment but i found that the Os shell commands ( !.. ) are not honoring my environment aliases. Bash or ZSH defined aliases for example.

Before aws-shell, years ago, I've writed myself a simple custom bash/zsh profile applied to a common centos-vm witch was a simple wrapper around aws-cli, enabling to switch between accounts ( export all the variables needed for awscli and a bunch of custom defined ones enabling some functionalities binded to the profile one's connecting to ) .. since now ...my team is using this simple approach to administer aws from the cli --> ssh@"awsconsole vm" with own AD username ... the profile script asks on login where to connect on aws-side, reading a list of pre-configured aws-profiles --> user inputs VPCNAME, role, IAM Creds, region etc... --> the wrapper exports the Environment Variables needed... and presents the shell ( the OS bash or zsh ) with aws-cli enabled and ready to work. Also swith between profiles is possible.

So long story short... i really would like to use aws-shell and get rid of my old solution... but there is a missing feature, really really usefull in my opinion ... the ability to specify custom commands per-aws profiles. ( aliases ...)

THE PROPOSAL

Why not use the dot command ".alias" --> opens the editor similar to .editor .. and be able to specify :

ALIASNAME="shell command pipeline"
ALIASNAME="Another cool command" 

This should be saved ( maybe ) inside ~/.aws/shell/aliases/ with the format CURRENTPROFILE.aliases

This way also would be an OS agnostic configuration..

The expected behaviour should be that when "aws-shell --profile WHATEVER" opens it loads the aliases corresponding to the profile you are connecting to, and when using the !COMMAND feature it resolves the defined correspondings. If a command is present, with the same name, in Os shell and alias definition.. the alias definited INSIDE aws-shell should take precedence... ( Override .. just like it is in plain bash/zsh )

So for example... if i define for profile "COMPANY01" the aliases ( Just using the .alias dot-command inside the aws-shell ):

ssh="ssh -Y -i /company01-aws-keys/$(echo whoami).pem " 

inside the aws-shell:

!ssh  centos@instance-name    -->  works as expected and also the configuration is portable from the aws-shell prospective.

Just a simple example... the ability to extend the aws-shell with custom PER-Profile aliases/overrides/custom-commands would be awsome.