Skip to content

Commit 6dce602

Browse files
committed
memo: Cleanup PIN entry
1 parent d747df5 commit 6dce602

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

memo

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,17 @@ join_by() { local IFS="$1"; shift; echo "$*"; }
3535
_copy() {
3636
echo
3737
read -q ans?"Copy to clipboard? "
38+
if [ "$ans" = n ]; then
39+
_cleanup 1
40+
return 0
41+
fi
3842
_cleanup
3943
[ "$ans" = n ] && return 0
4044
command -v xc &>/dev/null || return 1
4145
printf "${1:gs/%/%%}" | xc && echo "Copied!"
4246
}
4347

4448
show() {
45-
echo
4649
local list="$1"
4750
local c=`echo -E "$list" | wc -l`
4851
if (( $c > 1 )); then
@@ -56,20 +59,35 @@ show() {
5659
fi
5760
}
5861

62+
# Clean this line and $1 lines above.
5963
_cleanup() {
6064
printf "\r"
65+
66+
local i=${1:-0}
67+
while (( "$i" > 0 )); do
68+
printf "\r"
69+
i=$(( $i - 1 ))
70+
done
6171
}
6272

6373
_memo_get() {
6474
check_memo
6575
check gpg
6676

77+
local list
6778
if (( ! $# )); then
6879
local list=(`gpg -qd $memo | cut -d' ' -f1`)
6980
echo
7081
echo ${list[@]}
7182
elif (( $# == 1 )); then
72-
local list="`gpg -qd $memo | grep -iE ^$1`"
83+
# In case it shortcuts in a fail-loop:
84+
# gpg-connect-agent reloadagent /bye
85+
list="`gpg -qd --pinentry-mode error $memo 2>/dev/null | grep -iE ^$1`"
86+
if [ $? != 0 ]; then
87+
list="`gpg -qd $memo | grep -iE ^$1`"
88+
[ $? != 0 ] && exit 1
89+
_cleanup 2
90+
fi
7391
show "$list"
7492
else
7593
local q=`join_by \| $*`

0 commit comments

Comments
 (0)