From e3011c5ead82c62c0eddb9119f0cd4cf5e87ec58 Mon Sep 17 00:00:00 2001 From: Erich Smith Date: Sat, 28 Apr 2012 10:35:01 -0400 Subject: [PATCH] more portable pass function --- plugins/available/base.plugin.bash | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/plugins/available/base.plugin.bash b/plugins/available/base.plugin.bash index 46cde30..441b3ff 100755 --- a/plugins/available/base.plugin.bash +++ b/plugins/available/base.plugin.bash @@ -23,17 +23,28 @@ myip () echo -e "Your public IP is: ${echo_bold_green} $res ${echo_normal}" } -pass () + +pickfrom () { - about generates password from random dictionary words - which gshuf &> /dev/null - if [ $? -eq 1 ] - then - echo "Error: shuf isn't installed!" - return 1 - fi + about picks random line from file + param 1: filename + example $ pickfrom /usr/share/dict/words + local file=$1 + [ -z "$file" ] && reference $FUNCNAME && return + length=$(cat $file | wc -l) + n=$(expr $RANDOM \* $length \/ 32768 + 1) + head -n $n $f | tail -1 +} - pass=$(shuf -n4 /usr/share/dict/words | tr '\n' ' ') +pass () +{ + about generates random password from dictionary words + param optional integer length + param if unset, defaults to 4 + example $ pass + example $ pass 6 + local i pass length=${1:-4} + pass=$(echo $(for i in $(eval echo "{1..$length}"); do pickfrom /usr/share/dict/words; done)) echo "With spaces (easier to memorize): $pass" echo "Without (use this as the pass): $(echo $pass | tr -d ' ')" } -- 2.17.1