#!/bin/sh
#
# choose a random file from a given directory using rnda(1d); ignores dot files
# dependencies: rnda

# directory is first argument; defaults to current directory
dir="${1:-.}"

# set the positional parameters to all the non-dotfiles in that directory
set -- "${dir}"/*

# check for an unexpanded glob (empty directory)
if ! [ -e "$1" ]; then
  printf >&2 'rndf: No files found in %s\n' "${dir}"
  exit 1
fi

# print a random argument from the current positional parameters
rnda "$@"
