XKCD password generator in fish shell
! /usr/bin/env fish
XKCD style password generator from shell.
Grabbed words from here: http://www.use-in-a-sentence.com/english-words/10000-words/the-most-frequent-10000-words-of-english.html
and placed them in "words.txt" which should be in the same location as this
script. Will consider adding it as a command line parameter in a future
version.
For argument parsing:
https://butterflyprogramming.neoname.eu/programming-with-fish-shell/
http://stackoverflow.com/questions/16048757/fish-function-option-param-parser
set number_postfix "f"
for item in $argv
switch "$item"
case -n
set number_postfix "t"
end
end
set currentdir (dirname (status --current-filename))
set separator "" # One character or it breaks later
set philedata (cat $current_dir/words.txt)
echo $philedata
set data_length (count $philedata)
echo "data length $data_length"
set randomitems (shuf -i 1-$datalength -n 4)
echo "random items $random_items"
set stringagg ""
for position in $randomitems
# echo $position
# echo $philedata[$position]
# echo "------------"
set stringagg "$stringagg""$philedata[$position]""$separator"
end
Hack to remove last separator:
set stringagg (echo $stringagg | rev | cut -c 2- | rev)
echo $string_agg
if [ $numberpostfix = "t" ]
echo "$stringagg""$separator"(shuf -i 1-100 -n 1)
else
echo "$string_agg"
end
Written by Dimitrios Mistriotis
Related protips
1 Response
Repository (includes words.txt): https://gitlab.com/dimitrios/xkcd_passgen/blob/master/xkcd_passgen