summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGearnode <bryan@frimin.fr>2020-03-18 23:07:05 +0100
committerGearnode <bryan@frimin.fr>2020-03-18 23:07:05 +0100
commit169ad6c47c3f57b1f65978248bb62d6e6adbe1c3 (patch)
tree42f832dd2e928ac4812d9952024bbac14b65a315
parentaa0bf369f0f30fb4ecac80786bb82e6c590cf82c (diff)
add main shell snippet
-rw-r--r--snippets/sh-mode/main34
1 files changed, 34 insertions, 0 deletions
diff --git a/snippets/sh-mode/main b/snippets/sh-mode/main
new file mode 100644
index 0000000..34916fd
--- /dev/null
+++ b/snippets/sh-mode/main
@@ -0,0 +1,34 @@
+# -*- mode: snippet -*-
+# name: main
+# key: main
+# --
+#!/bin/sh
+
+set -eu
+
+fatal() {
+ printf "$*\n" >/dev/stderr
+ exit 1
+}
+
+usage() {
+ cat <<EOF
+usage: $0 OPTIONS <arg-1>
+
+OPTIONS
+ -h display help
+EOF
+}
+
+OPTIND=1
+while getopts 'h' arg; do
+ case "$arg" in
+ h) usage; exit 0 ;;
+ ?) fatal "unknown options" ;;
+ esac
+done
+shift $((OPTIND - 1))
+
+if [ $# -lt 1 ]; then
+ fatal "missing argument(s)"
+fi