From 328ca19ad666d6d858c70d5758ed72bc0a9feaa7 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 30 Nov 2019 10:19:32 +0000 Subject: [PATCH] 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 }