Skip to content

Commit

Permalink
move the 'op' command to a variable.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Creemer committed Apr 23, 2024
1 parent d38a267 commit 6ab7091
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions 1pass
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ print_output=0
clip_time=30
OP_SESSION_NAME=$(echo "$domain" | cut -f1 -d'.' | tr '-' '_')
list_fields=0
OPBIN="op1"

usage()
{
Expand Down Expand Up @@ -169,7 +170,7 @@ USAGE

sanity_check()
{
programs=(op jq "$GPG" expect)
programs=($OPBIN jq "$GPG" expect)

if [ "$use_totp" == "1" ]; then
programs+=(oathtool)
Expand All @@ -193,7 +194,7 @@ sanity_check()
fi
done

opversion=$(op --version)
opversion=$("$OPBIN" --version)
if [ "${opversion:0:1}" -gt 1 ]; then
echo "Only 1Password CLI version 1 is supported (found $opversion)" 1>&2
exit 1
Expand All @@ -217,7 +218,7 @@ signin()
local script
if [ "${use_totp}" == "0" ]; then
script="
spawn op signin ${domain} ${email} ${se}
spawn ${OPBIN} signin ${domain} ${email} ${se}
expect \"${domain}:\"
send \"${pw}\n\"
expect {
Expand All @@ -233,7 +234,7 @@ signin()
"
else
local script="
spawn op signin ${domain} ${email} ${se}
spawn ${OPBIN} signin ${domain} ${email} ${se}
expect \"${domain}:\"
send \"${pw}\n\"
expect {
Expand Down Expand Up @@ -297,7 +298,7 @@ fetch_index()
echo "fetching index of all items" 1>&2
fi
local items
items=$(op list items --session="${token}" || echo -n "_fail_")
items=$("$OPBIN" list items --session="${token}" || echo -n "_fail_")
if [ "$items" == "_fail_" ]; then
echo "1pass: failed to fetch index of all items"
exit 1
Expand All @@ -320,7 +321,7 @@ fetch_item()
echo "fetching item $uuid" 1>&2
fi
local item
item=$(op get item "$uuid" --session="$token" || echo -n "_fail_")
item=$("$OPBIN" get item "$uuid" --session="$token" || echo -n "_fail_")
if [ "$item" == "_fail_" ]; then
echo "1pass: failed to fetch item $uuid"
exit 1
Expand Down Expand Up @@ -401,7 +402,7 @@ get_003()

ensure_item "$uuid"

get_result=$(gpg -qd "${cache_dir}/${uuid}.gpg" | jq -r "${q}" || echo -n "_fail_")
get_result=$("$GPG" -qd "${cache_dir}/${uuid}.gpg" | jq -r "${q}" || echo -n "_fail_")
}

#
Expand All @@ -415,7 +416,7 @@ get_110()

ensure_item "$uuid"

get_result=$(gpg -qd "${cache_dir}/${uuid}.gpg" | jq -r "${q}" || echo -n "_fail_")
get_result=$("$GPG" -qd "${cache_dir}/${uuid}.gpg" | jq -r "${q}" || echo -n "_fail_")
}

#
Expand Down Expand Up @@ -491,7 +492,7 @@ get_totp()
echo "fetching TOTP for $uuid" 1>&2
fi
local totp
totp=$(op get totp "$uuid" --session="$token" || echo -n "_fail_")
totp=$("$OPBIN" get totp "$uuid" --session="$token" || echo -n "_fail_")
if [ "$item" == "_fail_" ]; then
echo "1pass: failed to fetch TOTP for $uuid"
exit 1
Expand Down

0 comments on commit 6ab7091

Please sign in to comment.