From 328ca19ad666d6d858c70d5758ed72bc0a9feaa7 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 30 Nov 2019 10:19:32 +0000 Subject: [PATCH 1/6] pash: clear clipboard after a timer --- README.md | 24 +++++++++++++++++++----- pash | 23 +++++++++++++++++------ 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 216ac9b..28593b9 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,7 @@ pash * [How do I set the password length?](#how-do-i-set-the-password-length) * [How do I change the password store location?](#how-do-i-change-the-password-store-location) * [How do I change the clipboard tool?](#how-do-i-change-the-clipboard-tool) + * [How do I change the clipboard timeout?](#how-do-i-change-the-clipboard-timeout) * [How do I change the password generation pattern?](#how-do-i-change-the-password-generation-pattern) * [How do I rename an entry?](#how-do-i-rename-an-entry) * [How can I migrate from `pass` to `pash`?](#how-can-i-migrate-from-pass-to-pash) @@ -61,11 +62,12 @@ COMMANDS OPTIONS -Using a key pair: export PASH_KEYID=XXXXXXXX -Password length: export PASH_LENGTH=50 -Password pattern: export PASH_PATTERN=_A-Z-a-z-0-9 -Store location: export PASH_DIR=~/.local/share/pash -Clipboard tool: export PASH_CLIP='xclip -selection clipboard' +Using a key pair: export PASH_KEYID=XXXXXXXX +Password length: export PASH_LENGTH=50 +Password pattern: export PASH_PATTERN=_A-Z-a-z-0-9 +Store location: export PASH_DIR=~/.local/share/pash +Clipboard tool: export PASH_CLIP='xclip -selection clipboard' +Clipboard timeout: export PASH_TIMEOUT=10 ``` ## FAQ @@ -136,6 +138,18 @@ export PASH_CLIP='xclip -selection clipboard' PASH_CLIP='xclip -selection clipboard' pash copy github ``` +### How do I change the clipboard timeout? + +Set the environment variable `PASH_TIMEOUT` to a command. + +```sh +# Default: '10' +export PASH_TIMEOUT=10 + +# This can also be used as a one-off. +PASH_TIMEOUT=5 pash copy github +``` + ### How do I change the password generation pattern? Set the environment variable `PASH_PATTERN` to a valid `tr` string. diff --git a/pash b/pash index 0cad611..a5bcd4f 100755 --- a/pash +++ b/pash @@ -58,7 +58,17 @@ pw_copy() { # Disable warning against word-splitting as it is safe # and intentional (globbing is disabled). # shellcheck disable=2086 - pw_show "$1" | ${PASH_CLIP:-xclip -selection clipboard} + : "${PASH_CLIP:=xclip -selection clipboard}" + + # Wait in the background for the password timeout and + # clear the clipboard when the timer runs out. + ( + printf 'Clearing clipboard in %d seconds.\n' "${PASH_TIMEOUT:=10}" + sleep "$PASH_TIMEOUT" + printf '' | $PASH_CLIP + ) & + + pw_show "$1" | $PASH_CLIP } pw_list() { @@ -119,11 +129,12 @@ pash 2.1.0 - simple password manager. => [l]ist - List all entries. => [s]how [name] - Show password for an entry. -Using a key pair: export PASH_KEYID=XXXXXXXX -Password length: export PASH_LENGTH=50 -Password pattern: export PASH_PATTERN=_A-Z-a-z-0-9 -Store location: export PASH_DIR=~/.local/share/pash -Clipboard tool: export PASH_CLIP='xclip -selection clipboard' +Using a key pair: export PASH_KEYID=XXXXXXXX +Password length: export PASH_LENGTH=50 +Password pattern: export PASH_PATTERN=_A-Z-a-z-0-9 +Store location: export PASH_DIR=~/.local/share/pash +Clipboard tool: export PASH_CLIP='xclip -selection clipboard' +Clipboard timeout: export PASH_TIMEOUT=10 " exit 1 } From 05be033cd617290d526dcee929c753a5ed5d2118 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 30 Nov 2019 10:35:19 +0000 Subject: [PATCH 2/6] pash: abort if PASH_TIMEOUT is an invalid argument to sleep --- pash | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pash b/pash index a5bcd4f..f0296a1 100755 --- a/pash +++ b/pash @@ -60,11 +60,16 @@ pw_copy() { # shellcheck disable=2086 : "${PASH_CLIP:=xclip -selection clipboard}" + printf 'Clearing clipboard in "%s" seconds.\n' \ + "${PASH_TIMEOUT:=10}" + # Wait in the background for the password timeout and # clear the clipboard when the timer runs out. + # + # If the 'sleep' fails, kill the script. This is the + # simplest method of aborting from a subshell. ( - printf 'Clearing clipboard in %d seconds.\n' "${PASH_TIMEOUT:=10}" - sleep "$PASH_TIMEOUT" + sleep "$PASH_TIMEOUT" || kill 0 printf '' | $PASH_CLIP ) & From 34d1e4484a8a140b1b7dcbc4e3bdf2964903c284 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 30 Nov 2019 10:41:33 +0000 Subject: [PATCH 3/6] pash: Use brace group instead of subshell and send /dev/null to clipboard manager --- pash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pash b/pash index f0296a1..b4c11eb 100755 --- a/pash +++ b/pash @@ -68,10 +68,10 @@ pw_copy() { # # If the 'sleep' fails, kill the script. This is the # simplest method of aborting from a subshell. - ( + { sleep "$PASH_TIMEOUT" || kill 0 - printf '' | $PASH_CLIP - ) & + $PASH_CLIP Date: Sat, 30 Nov 2019 11:09:14 +0000 Subject: [PATCH 4/6] pash: simpler xclip command --- README.md | 8 ++++---- pash | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 28593b9..c8b3e91 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ Using a key pair: export PASH_KEYID=XXXXXXXX Password length: export PASH_LENGTH=50 Password pattern: export PASH_PATTERN=_A-Z-a-z-0-9 Store location: export PASH_DIR=~/.local/share/pash -Clipboard tool: export PASH_CLIP='xclip -selection clipboard' +Clipboard tool: export PASH_CLIP='xclip -sel c' Clipboard timeout: export PASH_TIMEOUT=10 ``` @@ -131,11 +131,11 @@ PASH_DIR=/mnt/drive/pash pash list Set the environment variable `PASH_CLIP` to a command. ```sh -# Default: 'xclip -selection clipboard'. -export PASH_CLIP='xclip -selection clipboard' +# Default: 'xclip -sel c'. +export PASH_CLIP='xclip -sel c' # This can also be used as a one-off. -PASH_CLIP='xclip -selection clipboard' pash copy github +PASH_CLIP='xclip -sel c' pash copy github ``` ### How do I change the clipboard timeout? diff --git a/pash b/pash index b4c11eb..c14fb42 100755 --- a/pash +++ b/pash @@ -58,7 +58,7 @@ pw_copy() { # Disable warning against word-splitting as it is safe # and intentional (globbing is disabled). # shellcheck disable=2086 - : "${PASH_CLIP:=xclip -selection clipboard}" + : "${PASH_CLIP:=xclip -sel c}" printf 'Clearing clipboard in "%s" seconds.\n' \ "${PASH_TIMEOUT:=10}" @@ -138,7 +138,7 @@ Using a key pair: export PASH_KEYID=XXXXXXXX Password length: export PASH_LENGTH=50 Password pattern: export PASH_PATTERN=_A-Z-a-z-0-9 Store location: export PASH_DIR=~/.local/share/pash -Clipboard tool: export PASH_CLIP='xclip -selection clipboard' +Clipboard tool: export PASH_CLIP='xclip -sel c' Clipboard timeout: export PASH_TIMEOUT=10 " exit 1 From 00746c2ca4af4393eb845b2f27fa672a2cd01f5e Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 30 Nov 2019 11:36:29 +0000 Subject: [PATCH 5/6] pash: Add ability to disable the timeout --- README.md | 7 +++++-- pash | 10 +++++----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index c8b3e91..cd6b654 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ Password length: export PASH_LENGTH=50 Password pattern: export PASH_PATTERN=_A-Z-a-z-0-9 Store location: export PASH_DIR=~/.local/share/pash Clipboard tool: export PASH_CLIP='xclip -sel c' -Clipboard timeout: export PASH_TIMEOUT=10 +Clipboard timeout: export PASH_TIMEOUT=10 ('off' to disable) ``` ## FAQ @@ -140,12 +140,15 @@ PASH_CLIP='xclip -sel c' pash copy github ### How do I change the clipboard timeout? -Set the environment variable `PASH_TIMEOUT` to a command. +Set the environment variable `PASH_TIMEOUT` to a valid `sleep` interval or `off` to disable the feature. ```sh # Default: '10' export PASH_TIMEOUT=10 +# Disable timeout. +export PASH_TIMEOUT=off + # This can also be used as a one-off. PASH_TIMEOUT=5 pash copy github ``` diff --git a/pash b/pash index c14fb42..0ba0ba1 100755 --- a/pash +++ b/pash @@ -60,15 +60,15 @@ pw_copy() { # shellcheck disable=2086 : "${PASH_CLIP:=xclip -sel c}" - printf 'Clearing clipboard in "%s" seconds.\n' \ - "${PASH_TIMEOUT:=10}" - # Wait in the background for the password timeout and # clear the clipboard when the timer runs out. # # If the 'sleep' fails, kill the script. This is the # simplest method of aborting from a subshell. - { + [ "$PASH_TIMEOUT" != off ] && { + printf 'Clearing clipboard in "%s" seconds.\n' \ + "${PASH_TIMEOUT:=10}" + sleep "$PASH_TIMEOUT" || kill 0 $PASH_CLIP Date: Sat, 30 Nov 2019 11:41:28 +0000 Subject: [PATCH 6/6] pash: raise default timeout to 15 --- README.md | 6 +++--- pash | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index cd6b654..c98c350 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,7 @@ Password length: export PASH_LENGTH=50 Password pattern: export PASH_PATTERN=_A-Z-a-z-0-9 Store location: export PASH_DIR=~/.local/share/pash Clipboard tool: export PASH_CLIP='xclip -sel c' -Clipboard timeout: export PASH_TIMEOUT=10 ('off' to disable) +Clipboard timeout: export PASH_TIMEOUT=15 ('off' to disable) ``` ## FAQ @@ -143,8 +143,8 @@ PASH_CLIP='xclip -sel c' pash copy github Set the environment variable `PASH_TIMEOUT` to a valid `sleep` interval or `off` to disable the feature. ```sh -# Default: '10' -export PASH_TIMEOUT=10 +# Default: '15' +export PASH_TIMEOUT=15 # Disable timeout. export PASH_TIMEOUT=off diff --git a/pash b/pash index 0ba0ba1..80a7e03 100755 --- a/pash +++ b/pash @@ -67,7 +67,7 @@ pw_copy() { # simplest method of aborting from a subshell. [ "$PASH_TIMEOUT" != off ] && { printf 'Clearing clipboard in "%s" seconds.\n' \ - "${PASH_TIMEOUT:=10}" + "${PASH_TIMEOUT:=15}" sleep "$PASH_TIMEOUT" || kill 0 $PASH_CLIP