commit d991320a3d58a8c995c4b4b8049ebe7de85ff633 parent 5cd886db99807f6ea95bb85c3f69c799be5838ce Author: Matthew Carlson <matt@mcarlson.xyz> Date: Tue, 7 Sep 2021 23:19:57 -0400 fixed pass copying nothing after pressing esc Diffstat:
M | .local/bin/pass.sh | | | 78 | ++++++++++++++++++++++++++++++++++++++++++------------------------------------ |
1 file changed, 42 insertions(+), 36 deletions(-)
diff --git a/.local/bin/pass.sh b/.local/bin/pass.sh @@ -14,51 +14,57 @@ get_credential() { } main() { - i=0 - for site in "${CREDENTIALS_DIR}"/*.gpg; do - site="${site%.*}" - if [ ${i} -eq 0 ]; then sites="${sites}${site##*/}" - else sites="${sites}${NEWLINE}${site##*/}" - fi - i=$((i+1)) - done + while :; do + i=0 + for site in "${CREDENTIALS_DIR}"/*.gpg; do + site="${site%.*}" + if [ ${i} -eq 0 ]; then sites="${sites}${site##*/}" + else sites="${sites}${NEWLINE}${site##*/}" + fi + i=$((i+1)) + done - site="$(printf '%s\n' "${sites}" | dmenu -c -l 10)" + if ! site="$(printf '%s\n' "${sites}" | dmenu -c -l 10)"; then break; fi - credentials="$(gpg -dq "${CREDENTIALS_DIR}"/"${site}".gpg)" + credentials="$(gpg -dq "${CREDENTIALS_DIR}"/"${site}".gpg)" - credential_types="$(printf '%s\n' "${credentials}" | awk -F ':' '{ print $1 }')" + credential_types="$(printf '%s\n' "${credentials}" | awk -F ':' '{ print $1 }')" - squestions="$(printf '%s\n' "${credential_types}" | grep -c 'squestion*')" + squestions="$(printf '%s\n' "${credential_types}" | grep -c 'squestion*')" - credential_options="$(printf '%s\n' "${credential_types}" | ( while read -r type; do - case "${type}" in - 'uname') printf 'Username\n' ;; - 'pw') printf 'Password\n' ;; - 'email') printf 'Email\n' ;; - 'squestion'*) i=1 - while [ ${i} -le ${squestions} ]; do - printf '%s\n' "Security Question ${i}" - i=$((i+1)) - done - break - ;; - esac - done - printf '%s\n' "${credential_options}" ))" + credential_options="$(printf '%s\n' "${credential_types}" | ( while read -r type; do + case "${type}" in + 'uname') printf 'Username\n' ;; + 'pw') printf 'Password\n' ;; + 'email') printf 'Email\n' ;; + 'squestion'*) i=1 + while [ ${i} -le ${squestions} ]; do + printf '%s\n' "Security Question ${i}" + i=$((i+1)) + done + break + ;; + esac + done + printf '%s\n' "${credential_options}" ))" - credential_option="$(printf '%s\n' "${credential_options}" | dmenu -c -l 10 -p 'Credentials')" + if ! credential_option="$(printf '%s\n' "${credential_options}" | dmenu -c -l 10 -p 'Credentials')"; then + unset credential_options + continue + fi - if printf '%s\n' "${credential_option}" | grep -q '\<[0-9]\>'; then num="$(printf '%s\n' "${credential_option}" | awk '{ print $3 }')" ; fi + if printf '%s\n' "${credential_option}" | grep -q '\<[0-9]\>'; then num="$(printf '%s\n' "${credential_option}" | awk '{ print $3 }')" ; fi - case "${credential_option}" in - 'Username') get_credential 'uname' ;; - 'Password') get_credential 'pw' ;; - 'Email') get_credential 'email' ;; - "Security Question ${num}") get_credential "sanswer${num}" ;; - esac + case "${credential_option}" in + 'Username') get_credential 'uname' ;; + 'Password') get_credential 'pw' ;; + 'Email') get_credential 'email' ;; + "Security Question ${num}") get_credential "sanswer${num}" ;; + esac - if printf '%s\n' "${credential}" | xclip -selection clipboard; then { herbe "${credential_option} for "${site}" copied to clipboard" & } ; fi + if printf '%s\n' "${credential}" | xclip -selection clipboard; then { herbe "${credential_option} for "${site}" copied to clipboard" & } ; fi + break + done } main "${@}"