diff --git a/home/program/bash/module/Random.nix b/home/program/bash/module/Random.nix index 8346d43..b60b923 100644 --- a/home/program/bash/module/Random.nix +++ b/home/program/bash/module/Random.nix @@ -1,5 +1,16 @@ { ... }: { text = '' + # Generate random string. + # Usage: random + 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]} } ''; }