original idea: https://efcl.info/2023/01/31/remove-secret-from-local/
Last active
May 24, 2025 01:53
-
-
Save ka2n/a8e50bc98561cc218d562282632cb4c3 to your computer and use it in GitHub Desktop.
opr-fish
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if type -q op | |
function opr | |
argparse -n oprr -x 'e,g,h' 'e/env=' 'g/global' 'h/help' -- $argv | |
or return 1 | |
if test -n "$_flag_h" | |
echo "Usage: opr [-e|--env ENV_FILE] [-g|--global] -- COMMAND" | |
return 0 | |
end | |
if not op whoami > /dev/null | |
op signin | |
op whoami | |
end | |
# if $_flag_g is set, use global env file | |
# if $_flag_e is set, use the specified env file | |
# if neither is set, use the default env file | |
# default env file is "$PWD/.env" or "$HOME/.env.1password" | |
if test -n "$_flag_g" | |
set env_file "$HOME/.env.1password" | |
else if test -n "$_flag_e" | |
set env_file "$_flag_e" | |
else | |
# Start from current directory and search up to git root | |
set current_dir $PWD | |
set env_file "" | |
# Try to get git root directory (will fail if not in a git repo) | |
set git_root (git rev-parse --show-toplevel 2>/dev/null) | |
# If we're in a git repository, search from current dir up to git root | |
if test -n "$git_root" | |
while test "$current_dir" != "$git_root" | |
if test -f "$current_dir/.env.1password" | |
set env_file "$current_dir/.env.1password" | |
break | |
end | |
# Move up to parent directory | |
set current_dir (dirname $current_dir) | |
end | |
# Check at git root as well (final check) | |
if test -z "$env_file" -a -f "$git_root/.env.1password" | |
set env_file "$git_root/.env.1password" | |
end | |
end | |
# If no file found in path to git root, use home directory | |
if test -z "$env_file" | |
set env_file "$HOME/.env.1password" | |
end | |
end | |
set_color blue; echo "Using env file: $env_file"; set_color normal | |
op run --env-file="$env_file" --no-masking -- $argv | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment