Skip to content

Instantly share code, notes, and snippets.

@hugo
Last active August 29, 2015 14:09
Show Gist options
  • Save hugo/958d40c406418b79e5bf to your computer and use it in GitHub Desktop.
Save hugo/958d40c406418b79e5bf to your computer and use it in GitHub Desktop.
# autocompletion for bash from homebrew
if [ -f $(brew --prefix)/etc/bash_completion ]; then
. $(brew --prefix)/etc/bash_completion
fi
# generate a 3-character password section
_pw_section() {
env LC_CTYPE=C tr -dc "a-zA-Z0-9" < /dev/urandom | head -c 3
}
_pw_full() {
echo -n "$(_pw_section)-$(_pw_section)-$(_pw_section)-$(_pw_section)"
}
# generate a Safari style password
password() {
local usage="NAME
password
USAGE
password
Generate a password on the command line in Safari format
(four groups of three alphanumerics, dash separated)
e.g. OVt-5mH-bLn-oGh
password -c, --copy
Generate a password and copy it to the pasteboard"
if [ ! -z "$1" ]; then
if [ "$1" == "-c" ] || [ "$1" == "--copy" ] ; then
echo -n "$(_pw_full)" | pbcopy
return 0
else
echo "$usage"
return 0
fi
fi
echo "$(_pw_full)"
return 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment