Random : Add random_file.

This commit is contained in:
Dmitry Voronin 2023-12-19 16:18:57 +03:00
parent 187e8a48cf
commit 38a5791624

View file

@ -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]}
}