dotfiles

configuration files for shell, text editor, graphical environment, etc.
git clone git://src.adamsgaard.dk/dotfiles
Log | Files | Refs | README | LICENSE Back to index

commit d05458dac9b1f429fb0a2d6aa657d5267ba6f8b3
parent f6027483da1e6135969ee05dd7e3170145b0df04
Author: Anders Damsgaard <anders@adamsgaard.dk>
Date:   Mon, 16 Dec 2019 09:52:28 +0100

Add blank template for shell scripts with argument handling

Diffstat:
A.local/bin/template.sh | 66++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 66 insertions(+), 0 deletions(-)

diff --git a/.local/bin/template.sh b/.local/bin/template.sh @@ -0,0 +1,66 @@ +#!/bin/sh +# blank template for shell scripts + +version=0.1.0 + +show_help() { + echo "usage: ${0##*/} [OPTIONS] COMMAND ..." + echo "short description here." + echo + echo "OPTIONS are one or more of the following:" + echo " -h, --help show this message" + echo " -v, --version show version and license information" + echo " -V, --verbose show version and license information" + echo " -- do not consider any following args as options" +} + +show_version() { + echo "${0##*/} version $version" + echo "Licensed under the ISC License" + echo "written by Anders Damsgaard, anders@adamsgaard.dk" + echo "https://src.adamsgaard.dk/dotfiles" +} + +die() { + printf '%s\n' "$1" >&2 + exit 1 +} + +[ -f ~/.profile ] && . ~/.profile + +verbose=0 +while :; do + case "$1" in + -h|-\?|--help) + show_help + exit 0 + ;; + -v|--version) + show_version + exit 0 + ;; + -V|--verbose) + verbose=1 + exit 0 + ;; + --) # end all options + shift + break + ;; + -?*) + die 'Error: Unknown option specified' + ;; + *) # No more options + break + esac + shift +done + +if [ $# -lt 1 ]; then + show_help + exit 1 +fi + +for arg in "$@"; do + # handle arguments +done