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

weep incorrectly detects a shell #122

Open
igr opened this issue Sep 8, 2022 · 1 comment
Open

weep incorrectly detects a shell #122

igr opened this issue Sep 8, 2022 · 1 comment

Comments

@igr
Copy link

igr commented Sep 8, 2022

There is no -g option for the set command in Bash 5.1 on mac:

CleanShot 2022-09-13 at 09 44 55

This is what worked for me when executing from the bash script:

cmd=$(weep export arn:aws:iam::123:/aaa/sss)
cmd=${cmd//"set -gx"/"export"}
cmd=${cmd//" \""/=\"}
eval $cmd

As you see, I changed the output to:

export NAME=VALUE

format. It would be great if we could get such output as well.

@igr
Copy link
Author

igr commented Sep 14, 2022

@mikansoro figured out the core issue: weep uses SHELL env variable to figure out the shell (os.Getenv("SHELL")).

This is not the correct way of doing so. The SHELL variable indicates the default shell, not necessarily one that is used; like one specified in Shebang line of the script.

Solution: don't rely on the SHELL env. I tried quickly to find a go library that resolves shell correctly, but no luck. What works for me is the following shell command:

sh -c 'ps -p $$ -o ppid=' | xargs ps -o comm= -p

This should give the proper shell binary name, like /opt/homebrew/Cellar/fish/3.5.1/bin/fish

@igr igr changed the title weep export produces script code that is not working on mac bash 5.1 weep incorrectly detects a shell Sep 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant