Skip to content

Instantly share code, notes, and snippets.

@marcinantkiewicz
Last active April 17, 2026 14:42
Show Gist options
  • Select an option

  • Save marcinantkiewicz/dc0a4040e8acbf4fd9b56030fc2441be to your computer and use it in GitHub Desktop.

Select an option

Save marcinantkiewicz/dc0a4040e8acbf4fd9b56030fc2441be to your computer and use it in GitHub Desktop.
oprun - run command using 1password-provided credentials from usual location
oprun () {
op run --env-file="$(pwd)/.env" -- "$@"
}
op_refs () {
[[ "${1}" == "-h" ]] && {
echo " Prints 1Password references to stdout, I use it to cache the entries locally to quickly find entries for use in .env files";
echo " it will default to the Employee vault";
echo " Usage: op_refs [vault_name] > ~/.op_refs";
return 0;
}
local vault_name="${1:-Employee}";
if ! command -v op &> /dev/null || ! command -v jq &> /dev/null; then
echo "Error: 'op' and 'jq' must be installed and in your PATH." >&2;
return 1;
fi
echo "Fetching references from vault: '${vault_name}'" >&2;
local op_items;
op_items=$(op item list --vault "${vault_name}" --format json | jq -r '.[].id') || {
echo "Error: failed to list items in vault '${vault_name}'." >&2;
return 1;
}
local count=0;
while read -r op_item; do
local result;
result=$(op item get "$op_item" --format json 2>&1) || {
echo "Warning: failed to fetch item '$op_item': $result" >&2;
continue;
}
jq -r --arg id "$op_item" '.fields[]? | select(.reference | strings | startswith("op://")) | "- \($id) ref \(.reference)"' \
<<< "$result";
(( count ++ ));
done <<< "$op_items";
echo "Done. Fetched ${count} items" >&2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment