pash: abort if PASH_TIMEOUT is an invalid argument to sleep

This commit is contained in:
Dylan Araps 2019-11-30 10:35:19 +00:00
parent 328ca19ad6
commit 05be033cd6
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E
1 changed files with 7 additions and 2 deletions

9
pash
View File

@ -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
) &