synfinatic / aws-sso-cli

A powerful tool for using AWS Identity Center for the CLI and web console.
https://synfinatic.github.io/aws-sso-cli/
GNU General Public License v3.0
472 stars 57 forks source link

Add support for xonsh #1018

Open PodioSpaz opened 2 months ago

PodioSpaz commented 2 months ago

Please add support for xonsh.

Currently, the eval and exec commands return fatal errors when using xonsh shell.

~
xsh ❯ aws-sso --sso=prd eval
FATAL   invalid or unsupported shell.  Please file a bug!

~
xsh ❯ aws-sso --sso=prd exec
FATAL   exec: no command

Thanks

synfinatic commented 2 months ago

Hi @PodioSpaz,

Thanks for the feature request. eval command will definitely not work right now until I can add support. exec command is bailing out because xonsh doesn't set the $SHELL environment variable so without some command after exec it will fail. You can get around this by:

aws-sso --sso=prd exec xonsh or by running the specific command directly: aws-sso --sso=prd exec aws sts get-caller-identity

synfinatic commented 2 months ago

@PodioSpaz: So I had a similar issue with fish... looks like xonsh does not set the $SHELL environment variable which per-the documentation is the default command to run for aws-sso exec and enable other features of aws-sso.

So since you're the de-facto resident xonsh expert, what is the correct/supported way to detect that a command is running inside of the xonsh shell?

PodioSpaz commented 2 months ago

Hello @synfinatic,

As it turns out, xonsh does not have a built-in exec command.

I was able to get aws-sso exec to work by adding the following to ~/.xonshrc.

# Adding for aws-sso support
aliases['exec'] = aliases['xexec']
$SHELL = f"{$(which xonsh)}"

Additional resources on xexec: https://github.com/xonsh/xonsh/issues/84 https://xon.sh/aliases.html#exec-and-xexec

This solution does not work with https://starship.rs/

what is the correct/supported way to detect that a command is running inside of the xonsh shell?

I don't know, but I'll investigate. At the moment, the best way I know of is to test for the existence of $XONSH_VERSION

synfinatic commented 2 months ago

$XONSH_VERSION should work nicely.

Not sure I followed the issue about the missing exec command though? aws-sso exec is just defaulting to starting a new copy of the shell (as defined by $SHELL) and passing in the necessary environment variables so they are ready to go.

If you were to do aws-sso exec -p <profile> aws sts get-caller-identity then it ignores the $SHELL and instead run the aws command with the appropriate ENV vars set for that single command.

synfinatic commented 2 months ago

btw, @PodioSpaz are you willing to do the necessary shell integration to enable tab completion and the helper commands (aws-sso-profile and aws-sso-clear) You can look at the existing bash/zsh/fish code for inspiration: https://github.com/synfinatic/aws-sso-cli/tree/main/internal/helper

PodioSpaz commented 2 months ago

btw, @PodioSpaz are you willing to do the necessary shell integration to enable tab completion and the helper commands (aws-sso-profile and aws-sso-clear) You can look at the existing bash/zsh/fish code for inspiration: https://github.com/synfinatic/aws-sso-cli/tree/main/internal/helper

@synfinatic, Yes, I’ll take that on.

github-actions[bot] commented 1 month ago

This issue is stale because it has been open for 14 days with no response from the reporter. It will be automatically closed in 14 days from this message.