helm/bin/pass-get

28 lines
630 B
Plaintext
Raw Normal View History

#!/usr/bin/env bash
# Fetches the FIELD in ENTRY. It expects pass fields to be colon-delimited.
if (( $# != 2 )); then
>&2 echo "Expected two arguments"
>&2 echo "pass get ENTRY FIELD"
exit 1
fi
entry=$1
field=$2
secrets="$(pass show $entry)"
if [[ ! $secrets ]]; then
notify-send --urgency=critical "Failed to retrieve $entry"
exit 2
fi
2018-01-23 19:51:22 -08:00
case $field in
password) printf "%s" "$(head -n1 <<<"$secrets")" ;;
otp) printf "%s" "$(pass otp "$entry")" ;;
*) printf "%s" "$(awk -v "key=$field:" '$1 == key {print $2}' <<<"$secrets")" ;;
esac | xsel -i -b -t 15000
#
echo "Copied $entry:$field to clipboard for 15s"