Add more utility functions
This commit is contained in:
parent
f08765159a
commit
d2965c9233
15
rowbot
15
rowbot
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue