From 38a579162416e891282e2236157e5b3d6bb41857 Mon Sep 17 00:00:00 2001 From: desktop Date: Tue, 19 Dec 2023 16:18:57 +0300 Subject: [PATCH] Random : Add random_file. --- .config/bash/module/Random.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .config/bash/module/Random.sh diff --git a/.config/bash/module/Random.sh b/.config/bash/module/Random.sh new file mode 100644 index 0000000..2162f62 --- /dev/null +++ b/.config/bash/module/Random.sh @@ -0,0 +1,10 @@ +# Picks a random file or directory. +function random_file() { + local IFS=$'\n' + local dirs=($(ls)) + local total=${#dirs[@]} + ((total--)) + local index=$(shuf -i 0-${total} -n 1) + + echo ${dirs[$index]} +}