-
Notifications
You must be signed in to change notification settings - Fork 3
/
pwgen
executable file
·67 lines (55 loc) · 1.77 KB
/
pwgen
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh
VERSION_NUMBER=0.1.0
usage() {
cat << EOF
Usage: pwgen [OPTIONS]
Options:
-h, --help Show this message
-v, --version Show version
EOF
}
# Change long options to short
for arg
do
delim=""
case "$arg" in
--help) args="${args}-h ";;
--version) args="${args}-v ";;
*) [[ "${arg:0:1}" == "-" ]] || delim="\""
args="${args}${delim}${arg}${delim} ";;
esac
done
eval set -- $args
# Parse command line options.
while getopts "hv" option; do
case "$option" in
h)
usage
exit 0;;
v)
echo "`basename $0` $VERSION_NUMBER"
exit 0;;
# getopts issues an error message
\?)
usage >&2
exit 1;;
esac
done
# get the total number of words in the dictionary
NUM=`cat /usr/share/dict/words | wc -l`;
# get a random first word less than 6 characters
FIRST_WORD=$(head -n`jot -r 1 1 $NUM` /usr/share/dict/words | awk 'length < 6' | tail -n1);
# get a random second word less than 6 characters
SECOND_WORD=$(head -n`jot -r 1 1 $NUM` /usr/share/dict/words | awk 'length < 6' | tail -n1);
# generate a random number between 1 and 99
RAND_NUM=$(jot -r 1 1 99);
# setup our characters
CHARS=( '!' '@' '#' '$' '%' '^' '&' '*' '-' '_' '=' '+' ']' '[' '}' '{' ':' ';' '"' '.' ',' '<' '>' '?' );
# get a random character
CHAR_RAND=${CHARS[$(jot -r 1 1 ${#CHARS[*]})]};
# write the generated password to the clipboard
echo $FIRST_WORD$RAND_NUM$CHAR_RAND$SECOND_WORD | pbcopy;
# write the generated password to the screen
EXPLETIVE=("Bam" "Giggity" "Woot" "Ha cha cha" "Word" "Boo Ya" "Holla" "Hooray" "Hurrah" "Huzzah" "Giddyup" "Yee haw" "Woo hoo" "Falafel" "Yes" "Hip-hip" "Whoopee" "Yippee")
EXP_RAND=${EXPLETIVE[$(jot -r 1 1 ${#EXPLETIVE[*]})]};
echo $EXP_RAND"! Your new password:" $FIRST_WORD$RAND_NUM$CHAR_RAND$SECOND_WORD;