~tardypad/dotfiles

ref: f37f64d54c959fb7ec9796c00b8a3f7d4bbbd08c dotfiles/templates/script -rwxr-xr-x 596 bytes
f37f64d5 — Damien Tardy-Panis Only show task name if -n option is set 10 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh

init_variables() {
  COMMAND=${0##*/}

  OPTION=
  OPERAND=
}

parse_command_line() {
  while getopts o: OPT; do
    case "${OPT}" in
      o) OPTION="${OPTARG}" ;;
      ?) exit_error ;;
    esac
  done

  shift $(( OPTIND - 1 ))

  OPERAND="$1"
}

validate_command_line() {
  if [ -z "${OPERAND}" ]; then
    exit_error 'missing operand'
  fi
}

exit_error() {
  [ -z "$1" ] || echo "${COMMAND}: $1"
  exit 1
} >&2

print_items() {
  printf 'option: %s\n' "${OPTION}"
  printf 'operand: %s\n' "${OPERAND}"
}

init_variables
parse_command_line "$@"
validate_command_line

print_items