Hi,

Based on the email I just saw from Danylo ("pass less") about a timeout
for `pass show`, I think it's a very nice feature to be incorporated
into pass. I often read emails that people don't like previous output of
pass to be visible on the screen. I feel the same about this, especially
when someone could look over your shoulder.This is an attempt to add the option 
`pass show -t` to clear stdout
after PASSWORD_STORE_CLIP_TIME seconds. The code is portable and doesn't
add any dependencies. The current implementation is blocking on purpose,
you can still prevent clearing of the output.
Please let me know what you think and if you would like to see
this addition.
Kind regards,
Timmo Verlaan
From f32aceae66fb5dcfeeee6a8127664934ef354927 Mon Sep 17 00:00:00 2001
From: Timmo Verlaan <[email protected]>
Date: Tue, 5 Jun 2018 12:36:26 +0200
Subject: [PATCH] add timeout option to pass show to clear output

---
 src/password-store.sh | 25 +++++++++++++++++++------
 1 file changed, 19 insertions(+), 6 deletions(-)

diff --git a/src/password-store.sh b/src/password-store.sh
index 19b3124..c1b5dfe 100755
--- a/src/password-store.sh
+++ b/src/password-store.sh
@@ -263,9 +263,9 @@ cmd_usage() {
                List passwords.
            $PROGRAM find pass-names...
                List passwords that match pass-names.
-           $PROGRAM [show] [--clip[=line-number],-c[line-number]] pass-name
-               Show existing password and optionally put it on the clipboard.
-               If put on the clipboard, it will be cleared in $CLIP_TIME 
seconds.
+           $PROGRAM [show] [--clip[=line-number],-c[line-number] | 
--timeout,-t] pass-name
+               Show existing password, optionally clear output after 
$CLIP_TIME seconds.
+               Or put on the clipboard, it will be cleared in $CLIP_TIME 
seconds.
            $PROGRAM grep search-string
                Search for password files containing search-string when 
decrypted.
            $PROGRAM insert [--echo,-e | --multiline,-m] [--force,-f] pass-name
@@ -345,13 +345,14 @@ cmd_init() {
 }
 
 cmd_show() {
-       local opts selected_line clip=0 qrcode=0
-       opts="$($GETOPT -o q::c:: -l qrcode::,clip:: -n "$PROGRAM" -- "$@")"
+       local opts selected_line clip=0 qrcode=0 timeout=0
+       opts="$($GETOPT -o q::c::t -l qrcode::,clip::,timeout -n "$PROGRAM" -- 
"$@")"
        local err=$?
        eval set -- "$opts"
        while true; do case $1 in
                -q|--qrcode) qrcode=1; selected_line="${2:-1}"; shift 2 ;;
                -c|--clip) clip=1; selected_line="${2:-1}"; shift 2 ;;
+               -t|--timeout) timeout=1; shift ;;
                --) shift; break ;;
        esac done
 
@@ -362,7 +363,19 @@ cmd_show() {
        check_sneaky_paths "$path"
        if [[ -f $passfile ]]; then
                if [[ $clip -eq 0 && $qrcode -eq 0 ]]; then
-                       $GPG -d "${GPG_OPTS[@]}" "$passfile" || exit $?
+                       if [[ $timeout -eq 0 ]]; then
+                               $GPG -d "${GPG_OPTS[@]}" "$passfile" || exit $?
+                       else
+                               local content="$($GPG -d "${GPG_OPTS[@]}" 
"$passfile")"
+                               [[ -n $content ]] || die "Decrypting failed or 
file is empty"
+                               printf "$content\n"
+                               sleep $CLIP_TIME
+                               local lines="$(printf "${content}\n" | wc -l | 
tr -d ' ')"
+                               printf "\e[${lines}A"
+                               printf "$content\n" | while IFS= read -r line; 
do
+                                       printf "%${#line}s\n"
+                               done
+                       fi
                else
                        [[ $selected_line =~ ^[0-9]+$ ]] || die "Clip location 
'$selected_line' is not a number."
                        local pass="$($GPG -d "${GPG_OPTS[@]}" "$passfile" | 
tail -n +${selected_line} | head -n 1)"
-- 
2.14.1

_______________________________________________
Password-Store mailing list
[email protected]
https://lists.zx2c4.com/mailman/listinfo/password-store

Reply via email to