mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2025-12-19 02:02:32 +01:00
feat(1password): automatically inject secrets for specific commands using op run
- Add functionality to wrap specified commands (e.g., terraform, env) with - Automatically inject secrets from environment variables into subprocesses - Implement toggle activation with Ctrl+O keybinding
This commit is contained in:
parent
f733dc340b
commit
3be91a697b
1 changed files with 52 additions and 0 deletions
|
|
@ -13,3 +13,55 @@ op completion zsh >| "$ZSH_CACHE_DIR/completions/_op" &|
|
|||
|
||||
# Load opswd function
|
||||
autoload -Uz opswd
|
||||
|
||||
|
||||
# List of commands to inject secrets into before running
|
||||
OP_RUN_WRAPPER_CMDS=()
|
||||
OP_RUN_WRAPPER_ORIGINAL_PROMPT=$PROMPT
|
||||
OP_RUN_WRAPPER_SYMBOL="🔑"
|
||||
|
||||
# Currently we take a simple approach and set aliases to override each command, this could be done with functions instead
|
||||
# Also ignoring the option to specify specific environment files with the `--env-file` flag
|
||||
set_op_aliases() {
|
||||
for cmd in "${OP_RUN_WRAPPER_CMDS[@]}"; do
|
||||
alias "$cmd"="op run -- $cmd"
|
||||
done
|
||||
}
|
||||
|
||||
unset_op_aliases() {
|
||||
for cmd in "${OP_RUN_WRAPPER_CMDS[@]}"; do
|
||||
unalias "$cmd" 2>/dev/null
|
||||
done
|
||||
}
|
||||
|
||||
set_prompt() {
|
||||
OP_RUN_WRAPPER_ORIGINAL_PROMPT=$PROMPT
|
||||
export PROMPT="(${OP_RUN_WRAPPER_SYMBOL}) ${PROMPT}"
|
||||
}
|
||||
|
||||
unset_prompt() {
|
||||
export PROMPT="${OP_RUN_WRAPPER_ORIGINAL_PROMPT}"
|
||||
}
|
||||
|
||||
toggle_secrets_injection() {
|
||||
if [[ -z "${OP_RUN_WRAPPER_CMDS[*]}" ]]; then
|
||||
echo "Error: OP_RUN_WRAPPER_CMDS is empty, please update the list of commands which require secrets injection."
|
||||
zle reset-prompt
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ -z "$OP_RUN_WRAPPER_ACTIVE" ]]; then
|
||||
export OP_RUN_WRAPPER_ACTIVE=true
|
||||
set_op_aliases
|
||||
set_prompt
|
||||
else
|
||||
unset OP_RUN_WRAPPER_ACTIVE
|
||||
unset_op_aliases
|
||||
unset_prompt
|
||||
fi
|
||||
|
||||
zle reset-prompt
|
||||
}
|
||||
|
||||
zle -N toggle_secrets_injection
|
||||
bindkey '^O' toggle_secrets_injection
|
||||
Loading…
Add table
Add a link
Reference in a new issue