Add more utility functions

This commit is contained in:
Nick Chambers 2021-07-04 05:13:57 -05:00 committed by Nick Chambers
parent f08765159a
commit d2965c9233
1 changed files with 15 additions and 0 deletions

15
rowbot
View File

@ -115,6 +115,16 @@ unset key file setting setting_var env_name env_var
# utility and helper functions
###
any_file() {
local files=( "${1:-.}"/* ) max idx
if (( ${#files[@]} > 1 )); then
(( max = ${#files[@]} - 1 ))
idx=$(random 0 "$max")
printf %s "${files[$idx]}"
fi
}
die() {
# error "$@"
exit "${STATUS:-42}"
@ -153,6 +163,11 @@ is_reloaded() {
[[ $RELOADED = yes ]] || (( LORE_LIVES > 1 ))
}
random() {
local min=$1 max=$2
(( (RANDOM % max) + min ))
}
run_callbacks() {
if (( ! $# )); then
return 1