fix field extraction getting confused by similar field names

This commit is contained in:
Joel Beckmeyer 2021-09-10 19:18:25 -04:00
parent 26f8aae606
commit 68bc2ff66b

View File

@ -1,6 +1,10 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail
TYPE_CMD="wtype -" TYPE_CMD="wtype -"
help=0
autotype=0
_trim() { _trim() {
local var="$*" local var="$*"
@ -36,14 +40,7 @@ _parse_fields() {
} }
_pass_field() { _pass_field() {
IFS=$'\n' _trim "$(pass show "$password" | tail -n+2 | grep "^${*}:.*$" | cut -d: -f1 -s --complement)"
plaintext="$(pass show $password | tail -n +2)"
for line in $plaintext; do
if [[ $line =~ ^${1}:* ]]; then
printf "$(_trim "$(printf "$line" | cut -d: -f1 -s --complement)")"
fi
done
unset IFS
} }
_pass_get() { _pass_get() {
@ -105,7 +102,7 @@ else
if [[ $field == "autotype" ]] || [[ $autotype -eq 1 ]]; then if [[ $field == "autotype" ]] || [[ $autotype -eq 1 ]]; then
username=$(_pass_get "username") username=$(_pass_get "username")
password=$(_pass_get "password") password=$(_pass_get "password")
printf "%b\t%b\n" $username $password | $TYPE_CMD printf "%b\t%b\n" "${username}" "${password}" | $TYPE_CMD
else else
_pass_get $field | $TYPE_CMD _pass_get $field | $TYPE_CMD
fi fi