more portable pass function
parent
a3c3caa0ab
commit
e3011c5ead
|
|
@ -23,17 +23,28 @@ myip ()
|
||||||
echo -e "Your public IP is: ${echo_bold_green} $res ${echo_normal}"
|
echo -e "Your public IP is: ${echo_bold_green} $res ${echo_normal}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pickfrom ()
|
||||||
|
{
|
||||||
|
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 ()
|
pass ()
|
||||||
{
|
{
|
||||||
about generates password from random dictionary words
|
about generates random password from dictionary words
|
||||||
which gshuf &> /dev/null
|
param optional integer length
|
||||||
if [ $? -eq 1 ]
|
param if unset, defaults to 4
|
||||||
then
|
example $ pass
|
||||||
echo "Error: shuf isn't installed!"
|
example $ pass 6
|
||||||
return 1
|
local i pass length=${1:-4}
|
||||||
fi
|
pass=$(echo $(for i in $(eval echo "{1..$length}"); do pickfrom /usr/share/dict/words; done))
|
||||||
|
|
||||||
pass=$(shuf -n4 /usr/share/dict/words | tr '\n' ' ')
|
|
||||||
echo "With spaces (easier to memorize): $pass"
|
echo "With spaces (easier to memorize): $pass"
|
||||||
echo "Without (use this as the pass): $(echo $pass | tr -d ' ')"
|
echo "Without (use this as the pass): $(echo $pass | tr -d ' ')"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue