Skip to content

feat: allow to specify shell for exporting env

Steve Xuereb requested to merge feat/specify-shell-for-env into main

What

Create a new flag --shell for env, sso env, gitlab env, google env to specify which shell to create the export variables in.

$ echo $SHELL  # Fish is the default shell
/opt/homebrew/bin/fish

$ go run main.go env --allow-terminal  "Dedicated/Sandbox/GitLab.com/PAT:Personal" # Defaults to shell
pmv: ⚠️   Connected to terminal, but bypass set, allowing.
pmv: ⚠️   SECRETS TO FOLLOW ------------------------------
pmv: 🔓 Fetching 1password items tag=Dedicated/Sandbox/GitLab.com/PAT:Personal
pmv: 🧩 Loaded item title="GitLab Access Token: GitLab.com PAT for Sandbox Access (api): https://gitlab.com: xxx"
set --export GITLAB_TOKEN xxx;
set --export GITLAB_USERNAME xxx;
pmv: 🔓 Complete, loaded items...

$ go run main.go env --allow-terminal --shell fish "Dedicated/Sandbox/GitLab.com/PAT:Personal"
pmv: ⚠️   Connected to terminal, but bypass set, allowing.
pmv: ⚠️   SECRETS TO FOLLOW ------------------------------
pmv: 🔓 Fetching 1password items tag=Dedicated/Sandbox/GitLab.com/PAT:Personal
pmv: 🧩 Loaded item title="GitLab Access Token: GitLab.com PAT for Sandbox Access (api): https://gitlab.com: xxx"
set --export GITLAB_TOKEN xxx;
set --export GITLAB_USERNAME xxx;
pmv: 🔓 Complete, loaded items...

$ go run main.go env --allow-terminal --shell bash "Dedicated/Sandbox/GitLab.com/PAT:Personal"
pmv: ⚠️   Connected to terminal, but bypass set, allowing.
pmv: ⚠️   SECRETS TO FOLLOW ------------------------------
pmv: 🔓 Fetching 1password items tag=Dedicated/Sandbox/GitLab.com/PAT:Personal
pmv: 🧩 Loaded item title="GitLab Access Token: GitLab.com PAT for Sandbox Access (api): https://gitlab.com: xxx"
export GITLAB_TOKEN=xxx
export GITLAB_USERNAME=xxx
pmv: 🔓 Complete, loaded items...

$ go run main.go env --allow-terminal --shell /opt/homebrew/bin/bash "Dedicated/Sandbox/GitLab.com/PAT:Personal" # Specify path
pmv: ⚠️   Connected to terminal, but bypass set, allowing.
pmv: ⚠️   SECRETS TO FOLLOW ------------------------------
pmv: 🔓 Fetching 1password items tag=Dedicated/Sandbox/GitLab.com/PAT:Personal
pmv: 🧩 Loaded item title="GitLab Access Token: GitLab.com PAT for Sandbox Access (api): https://gitlab.com: xxx"
export GITLAB_TOKEN=xxx
export GITLAB_USERNAME=xxx
pmv: 🔓 Complete, loaded items...

Why

When a script like scripts/sandbox/generate-sandbox-vars.sh calls pmv and is executed via a terminal with fish, the $SHELL variable is set to /path/to/fish. pmv is smart and returns the fish commands to set the variables, however the scripts are executing in a bash shell which results into the following errors:

$ ./scripts/sandbox/generate-sandbox-vars.sh
Checking 1password authentication status...
pmv: 🔓 Fetching 1password items tag=Dedicated/Amp/Sandbox/Env:Test
pmv: warn: no matching items found
pmv: 🔓 Complete, loaded items...
pmv: 🔓 Fetching 1password items tag=Dedicated/Sandbox/GitLab.com/PAT:Personal
pmv: 🧩 Loaded item title="GitLab Access Token: GitLab.com PAT for Sandbox Access (api): https://gitlab.com: sxuereb"
pmv: 🔓 Complete, loaded items...
./scripts/sandbox/generate-sandbox-vars.sh: line 35: set: --: invalid option
set: usage: set [-abefhkmnptuvxBCEHPT] [-o option-name] [--] [-] [arg ...]

We need a way to tell pmv for which shell to create these commands so that we can execute them in the bash script and not be dependent on the users' shell environment.

Merge request reports