diff --git a/dot_config/private_fish/functions/opx.fish b/dot_config/private_fish/functions/opx.fish index e7cf1ad1f5352d6912b3c6c2ceb9a8ce10f2b73d..ed0ffd37401541f0b14c9cbcd5b677fe753ddbb9 100644 --- a/dot_config/private_fish/functions/opx.fish +++ b/dot_config/private_fish/functions/opx.fish @@ -28,5 +28,26 @@ function opx --description "Run command with 1Password secret refs resolved" return 1 end - env $resolved_lines $argv + # Check if the command is a fish function + if functions -q $argv[1] + # Parse resolved values (originals are in $refs) + set -l resolved_values + for line in $resolved_lines + set -a resolved_values (string split -m1 '=' $line)[2] + end + # Set globals with resolved values + for i in (seq (count $vars_to_resolve)) + set -gx $vars_to_resolve[$i] $resolved_values[$i] + end + # Run command + $argv + set -l cmd_status $status + # Restore original op:// refs + for i in (seq (count $vars_to_resolve)) + set -gx $vars_to_resolve[$i] $refs[$i] + end + return $cmd_status + else + env $resolved_lines $argv + end end