blob: cec9e5462767994c7855cf1e6ddf196d0e2d64fc (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#!/bin/sh
# 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|pri]\n' "$(basename $0)">/dev/stderr
return 1
fi
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"
fi
|