You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think this is because the #!/usr/bin/env bash shebang line causes it to run in a subshell in which ~/.config/op/plugins.sh would not have been sourced.
As far as I know there isn't really any way around this other than having your script check if ~/.config/op/plugins.sh exists, and if so, source it again.
Those workarounds only work when you can modify the script. As 1Password Shell Plugins are based on alias, it seems a significant limitation for actual usage.
It is worth to think an alternative official way to make it work.
One way I thought is something like op plugins run <plugins> -- ./script
Reacted by Martijn Arts, Simon Barendse, Tiago Cussiol, Scott Lamb and Daniel Harvey
I think this is because the #!/usr/bin/env bash shebang line causes it to run in a subshell in which ~/.config/op/plugins.sh would not have been sourced.
This is correct. Furthermore, 1Password Shell Plugins are (currently) build to be used in interactive shells. Besides the problem you're now running into of the aliases not having been sourced, the plugin might also need to prompt (e.g. when you don't have a default credential configured), which is only possible in an interactive terminal.
I agree with both these comments:
It might be worth adding something like this to the dev documentation.
Those workarounds only work when you can modify the script. As 1Password Shell Plugins are based on alias, it seems a significant limitation for actual usage.
It is worth to think an alternative official way to make it work.
As an alternative workaround for now that doesn't require you to change your scripts, you could use a shim: create a file in your $PATH named doctl with the following contents:
op plugin run /usr/local/bin/doctl
It needs to have exec permissions (chmod +x) and it needs to take precedence in your path over the actual doctl binary
All I'm looking for is a way to execute a command (in my case terraform plan) and have op plugin inject the AWS_ environment variables into that command. Is there any way to do this currently or is this or a related ticket blocking that?
@lypanov We have just released our new beta solution for the Terraform shell plugin. This allows AWS to work with Terraform out of the box, and also comes up with a general solution for authenticating terraform providers. Would be awesome if you could give it a try and let us know how/if this simplifies your workflows by a bunch.
@lypanov We have just released our new beta solution for the Terraform shell plugin. This allows AWS to work with Terraform out of the box, and also comes up with a general solution for authenticating terraform providers. Would be awesome if you could give it a try and let us know how/if this simplifies your workflows by a bunch.
@AndyTitu Sorry for the delay in response, was recovering from illness. This works really well now thank you for the solution!
Activity
martijnarts commentedon Dec 19, 2022
Workaround is replacing the line with
op plugin run doctl account getmrjones2014 commentedon Dec 19, 2022
I think this is because the
#!/usr/bin/env bashshebang line causes it to run in a subshell in which~/.config/op/plugins.shwould not have beensourced.As far as I know there isn't really any way around this other than having your script check if
~/.config/op/plugins.shexists, and if so,sourceit again.mrjones2014 commentedon Dec 19, 2022
Alternatively, you could write it as a shell function in your
~/.bashrc/~/.zshrc/~/.config/fish/config.fishinstead of having it be a script.e.g. for bash/zsh
mydoctlalias() { doctl account get }or for Fish shell:
This way it would run in the current shell instead of a subshell and therefore your aliases from
~/.config/op/plugins.shwould be respected.martijnarts commentedon Dec 19, 2022
Yeah, I figured that would be the problem. It might be worth adding something like this to the dev documentation.
cussiol commentedon Dec 23, 2022
Those workarounds only work when you can modify the script. As 1Password Shell Plugins are based on
alias, it seems a significant limitation for actual usage.It is worth to think an alternative official way to make it work.
One way I thought is something like
op plugins run <plugins> -- ./scriptSimonBarendse commentedon Jan 6, 2023
This is correct. Furthermore, 1Password Shell Plugins are (currently) build to be used in interactive shells. Besides the problem you're now running into of the aliases not having been sourced, the plugin might also need to prompt (e.g. when you don't have a default credential configured), which is only possible in an interactive terminal.
I agree with both these comments:
martijnarts commentedon Jan 6, 2023
I start all my scripts with this now:
SimonBarendse commentedon Jan 6, 2023
As an alternative workaround for now that doesn't require you to change your scripts, you could use a shim: create a file in your
$PATHnameddoctlwith the following contents:It needs to have exec permissions (chmod +x) and it needs to take precedence in your path over the actual doctl binary
cussiol commentedon Feb 9, 2023
@SimonBarendse I tried that workaround but got an error:
lypanov commentedon Mar 30, 2023
All I'm looking for is a way to execute a command (in my case terraform plan) and have op plugin inject the AWS_ environment variables into that command. Is there any way to do this currently or is this or a related ticket blocking that?
kjvalencik commentedon Apr 20, 2023
My workaround for terraform is a wrapper script that calls
aws configure export-credentials --format envbefore executing the terraform command.I have an alias to this script set to
terraformin my shell config.AndyTitu commentedon May 24, 2023
@lypanov We have just released our new beta solution for the Terraform shell plugin. This allows AWS to work with Terraform out of the box, and also comes up with a general solution for authenticating terraform providers. Would be awesome if you could give it a try and let us know how/if this simplifies your workflows by a bunch.
lypanov commentedon Jan 8, 2024
@AndyTitu Sorry for the delay in response, was recovering from illness. This works really well now thank you for the solution!
scottisloud commentedon May 7, 2026
Hi everyone,
Looks like we have a conclusive answer and way forward here so I'll be closing this issue out.
Thanks all!