Random: Add random string generator.
This commit is contained in:
parent
fb0050a0a6
commit
77bfe23b2b
|
@ -1,5 +1,16 @@
|
|||
{ ... }: {
|
||||
text = ''
|
||||
# Generate random string.
|
||||
# Usage: random <LENGTH>
|
||||
function random() {
|
||||
local length="''${1}"
|
||||
if [[ "''${length}" = "" ]]; then
|
||||
help random
|
||||
return 2
|
||||
fi
|
||||
head /dev/urandom | tr -dc A-Za-z0-9 | head -c''${length}
|
||||
}
|
||||
|
||||
# Picks a random file or directory.
|
||||
function random_file() {
|
||||
local IFS=$'\n'
|
||||
|
@ -8,7 +19,7 @@
|
|||
((total--))
|
||||
local index=$(shuf -i 0-''${total} -n 1)
|
||||
|
||||
echo ''${dirs[$index]}
|
||||
printf "%s" ''${dirs[$index]}
|
||||
}
|
||||
'';
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue