pash: Add ability to disable the timeout

This commit is contained in:
Dylan Araps 2019-11-30 11:36:29 +00:00
parent 792ccead72
commit 00746c2ca4
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E
2 changed files with 10 additions and 7 deletions

View File

@ -67,7 +67,7 @@ Password length: export PASH_LENGTH=50
Password pattern: export PASH_PATTERN=_A-Z-a-z-0-9 Password pattern: export PASH_PATTERN=_A-Z-a-z-0-9
Store location: export PASH_DIR=~/.local/share/pash Store location: export PASH_DIR=~/.local/share/pash
Clipboard tool: export PASH_CLIP='xclip -sel c' Clipboard tool: export PASH_CLIP='xclip -sel c'
Clipboard timeout: export PASH_TIMEOUT=10 Clipboard timeout: export PASH_TIMEOUT=10 ('off' to disable)
``` ```
## FAQ ## FAQ
@ -140,12 +140,15 @@ PASH_CLIP='xclip -sel c' pash copy github
### How do I change the clipboard timeout? ### 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 ```sh
# Default: '10' # Default: '10'
export PASH_TIMEOUT=10 export PASH_TIMEOUT=10
# Disable timeout.
export PASH_TIMEOUT=off
# This can also be used as a one-off. # This can also be used as a one-off.
PASH_TIMEOUT=5 pash copy github PASH_TIMEOUT=5 pash copy github
``` ```

10
pash
View File

@ -60,15 +60,15 @@ pw_copy() {
# shellcheck disable=2086 # shellcheck disable=2086
: "${PASH_CLIP:=xclip -sel c}" : "${PASH_CLIP:=xclip -sel c}"
printf 'Clearing clipboard in "%s" seconds.\n' \
"${PASH_TIMEOUT:=10}"
# Wait in the background for the password timeout and # Wait in the background for the password timeout and
# clear the clipboard when the timer runs out. # clear the clipboard when the timer runs out.
# #
# If the 'sleep' fails, kill the script. This is the # If the 'sleep' fails, kill the script. This is the
# simplest method of aborting from a subshell. # 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 sleep "$PASH_TIMEOUT" || kill 0
$PASH_CLIP </dev/null $PASH_CLIP </dev/null
} & } &
@ -139,7 +139,7 @@ Password length: export PASH_LENGTH=50
Password pattern: export PASH_PATTERN=_A-Z-a-z-0-9 Password pattern: export PASH_PATTERN=_A-Z-a-z-0-9
Store location: export PASH_DIR=~/.local/share/pash Store location: export PASH_DIR=~/.local/share/pash
Clipboard tool: export PASH_CLIP='xclip -sel c' Clipboard tool: export PASH_CLIP='xclip -sel c'
Clipboard timeout: export PASH_TIMEOUT=10 Clipboard timeout: export PASH_TIMEOUT=10 ('off' to disable)
" "
exit 1 exit 1
} }