-
-
Save Oyonax/7a071ac030c826695fb7722c56387bd5 to your computer and use it in GitHub Desktop.
Bash script to generate a mnemonic passphrase à la https://xkcd.com/936
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
## | |
## generate mnemonic passphrases beginning with the given letters | |
## | |
## Author: Kevin Ernst | |
## Date: 27 May 2021 | |
## License: MIT | |
## Source: https://gist.github.com/ernstki/589bfb4adfb3869834c97bd106d58b7e | |
## | |
## Usage: pphrases a b c [...] | |
## | |
# shellcheck disable=SC2016 | |
_pphrases() { | |
local howmany=18 | |
local shuf='shuf' | |
local sed='sed' | |
# use 'gshuf' on macOS | |
if [[ $(uname -s) == Darwin ]]; then | |
shuf='gshuf' | |
sed='gsed' | |
fi | |
for (( i=0; i<howmany; i++ )); do | |
# take each input letter, | |
for l in "$@"; do | |
# find one word that starts with that; omit hyphenated words and | |
# words that have periods in them | |
grep -i ^"$l" /usr/share/dict/words | grep -v '[-.]' | $shuf -n1 | |
done | $sed -n 's/\(.\)\(.*\)/\U\1\L\2/;H;${x;s/^\n//;s/\n/-/g;p;}' | |
# ^ upper-case first character, then join with dashes | |
done | paste - - - | column -t | |
} | |
_pphrases "${@}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment