-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathrandom-file
executable file
·24 lines (21 loc) · 1.3 KB
/
random-file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#!/usr/bin/env bash
#########################################################################
# Random File Picker #
# #
# Randomly picks a file or directory in the given directory or $PWD #
# and displays it. #
# #
# I use this to let Fate decide which movie I'm going to watch! #
# #
# Part of HopeSeekr's BashScripts Collection #
# https://github.com/hopeseekr/BashScripts/ #
# #
# Copyright © 2020 Theodore R. Smith <theodore@phpexperts.pro> #
# GPG Fingerprint: 4BF8 2613 1C34 87AC D28F 2AD8 EB24 A91D D612 5690 #
# #
# License: Creative Commons Attribution v4.0 International #
#########################################################################
dir=${1-$PWD}
# @see https://stackoverflow.com/a/18617295/430062
files=($dir/*)
printf "%s\n" "${files[RANDOM % ${#files[@]}]}"