aws-sso-cli icon indicating copy to clipboard operation
aws-sso-cli copied to clipboard

Add support for xonsh

Open PodioSpaz opened this issue 1 year ago • 7 comments

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

PodioSpaz avatar Aug 09 '24 17:08 PodioSpaz

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 avatar Aug 09 '24 18:08 synfinatic

@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?

synfinatic avatar Aug 20 '24 01:08 synfinatic

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

PodioSpaz avatar Aug 20 '24 22:08 PodioSpaz

$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 avatar Aug 20 '24 23:08 synfinatic

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 avatar Aug 20 '24 23:08 synfinatic

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.

PodioSpaz avatar Aug 21 '24 12:08 PodioSpaz

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.

github-actions[bot] avatar Sep 05 '24 01:09 github-actions[bot]