aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2022-08-13 09:32:13 -0300
committerEuAndreh <eu@euandre.org>2022-08-13 09:32:13 -0300
commited38917a1ec50fd064181bb06052a4390248432c (patch)
tree6ab790572d0491916148295e8d2c92bfe8edcecd
parentbin/m: Add working utility (diff)
downloaddotfiles-ed38917a1ec50fd064181bb06052a4390248432c.tar.gz
dotfiles-ed38917a1ec50fd064181bb06052a4390248432c.tar.xz
bin/dice: Add working utility
-rwxr-xr-xbin/dice66
1 files changed, 66 insertions, 0 deletions
diff --git a/bin/dice b/bin/dice
new file mode 100755
index 0000000..93556a5
--- /dev/null
+++ b/bin/dice
@@ -0,0 +1,66 @@
+#!/bin/sh
+set -eu
+
+usage() {
+ cat <<-'EOF'
+ Usage:
+ dice [SIZE]
+ dice -h
+ EOF
+}
+
+help() {
+ cat <<-'EOF'
+
+ Options:
+ -h, --help show this message
+
+ SIZE the size of the dice (default: 6)
+
+
+ Examples:
+
+ Roll a dice of size 6:
+
+ $ dice
+
+ Roll a D20:
+
+ $ dice 20
+ EOF
+}
+
+
+for flag in "$@"; do
+ case "$flag" in
+ --)
+ break
+ ;;
+ --help)
+ usage
+ help
+ exit
+ ;;
+ *)
+ ;;
+ esac
+done
+
+while getopts 'h' flag; do
+ case "$flag" in
+ h)
+ usage
+ help
+ exit
+ ;;
+ *)
+ usage >&2
+ exit 2
+ ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+
+SIZE="${1:-6}"
+echo $(((RANDOM % SIZE) + 1))