Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit eef6b271a022adc3413601462a40ff31eed963e9 @ryankee committed Jan 29, 2012
Showing with 91 additions and 0 deletions.
  1. +19 −0 README.md
  2. +7 −0 makefile
  3. +65 −0 pwgen
@@ -0,0 +1,19 @@
+pwgen
+======
+Password generator for OSX
+
+Usage
+-----
+ Usage: pwgen [OPTIONS]
+
+ Options:
+ -h, --help Show this message
+ -v, --version Show version
+
+Installation
+------------
+Included in the repo is a `makefile` that allows you to install/uninstall
+
+ $ make install
+ $ make uninstall
+
@@ -0,0 +1,7 @@
+install:
+ # create a symlink
+ ln -s $(CURDIR)/pwgen /usr/local/bin/pwgen
+
+uninstall:
+ # remove symlink
+ rm /usr/local/bin/pwgen
@@ -0,0 +1,65 @@
+#!/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
+echo "Bam! Your new password:" $FIRST_WORD$RAND_NUM$CHAR_RAND$SECOND_WORD;

0 comments on commit eef6b27

Please sign in to comment.