diff options
Diffstat (limited to 'bin/pw')
-rwxr-xr-x | bin/pw | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/bin/pw b/bin/pw index 140f1dc..cec9e54 100755 --- a/bin/pw +++ b/bin/pw @@ -1,14 +1,25 @@ #!/bin/sh -# generates a password of length $1, sends it to stdout if $2 isn't clip. -# if it is clip, sends it to the X clipboard and clears it after 10 seconds. +# generates a password of length $1, sends it to stdout if $2 is blank. +# if $2 is clip, sends it to the X clipboard and clears it after 10 seconds. +# if $2 is anything else, sends it to the X primary selection and clears it after 10 seconds if [ "$1" = "-h" ]; then - printf 'usage: %s [-h]|LENGTH [clip]\n' "$(basename $0)">/dev/stderr&&return 1 + printf 'usage: %s [-h]|LENGTH [clip|pri]\n' "$(basename $0)">/dev/stderr + return 1 fi -PW=$(tr -cd "[:alnum:][:punct:]"</dev/urandom|fold -w $1|head -1) -if [ "$2" = "clip" ]; then - printf '%s' "$PW"|xclip -sel clip -i&¬ify-send "Password Generated" "$1-character password generated. It will clear in 10 seconds." - sleep 10 - printf "\0"|xclip -sel clip -i&¬ify-send "Clipboard Cleared" "Generated password cleared from clipboard." +PW=$(tr -cd "[:alnum:][:punct:]"</dev/urandom|fold -w "$1"|head -1) +if [ -n "$2" ]; then + # streamline selection variation by using $SEL + if [ "$2" = "clip" ]; then + SEL="-sel clip" + else + SEL="" + fi + # backgrounds so the user doesn't have to wait 10 seconds to get a prompt again + { + printf "%s" "$PW"|xclip $SEL -i&¬ify-send "Password Generated" "$1-character password generated. It will clear in 10 seconds." + sleep 10 + printf '\0'|xclip $SEL -i&¬ify-send "Clipboard Cleared" "Generated password cleared from clipboard." + } & else - printf '%s\n' "$PW" + printf '%s\n' "$PW" fi |