summaryrefslogtreecommitdiff
path: root/bin/extra/notify-send
blob: e058d7934937b35b5920b56c6fd18921a945e621 (plain)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/sh
# Shell script to redirect notify-send calls to herbe. The purpose is to ignore
# options passed to notify-send.
#
# Option parser generated by getoptions
# URL: https://github.com/ko1nksm/getoptions
# LICENSE: Creative Commons Zero v1.0 Universal

usage() {
    printf '%s\n' "${0##*/}: notify-send replacement for herbe" "accepts but ignores all notify-send options."
}

REST=''
parse() {
  OPTIND=$(($#+1))
  while [ $# -gt 0 ] && OPTARG=; do
    case $1 in
      --?*=*) OPTARG=$1; shift
        eval 'set -- "${OPTARG%%\=*}" "${OPTARG#*\=}"' ${1+'"$@"'}
        ;;
      -[utich]?*) OPTARG=$1; shift
        eval 'set -- "${OPTARG%"${OPTARG#??}"}" "${OPTARG#??}"' ${1+'"$@"'}
        ;;
      -[!-]?*) OPTARG=$1; shift
        eval 'set -- "${OPTARG%"${OPTARG#??}"}" "-${OPTARG#??}"' ${1+'"$@"'}
        OPTARG= ;;
    esac
    case $1 in
      -u | --urgency)
        [ $# -le 1 ] && set -- "$1" required && break
        OPTARG=$2
        _=$OPTARG
        shift ;;
      -t | --expire-time)
        [ $# -le 1 ] && set -- "$1" required && break
        OPTARG=$2
        _=$OPTARG
        shift ;;
      -a | --app-name)
        [ $# -le 1 ] && set -- "$1" required && break
        OPTARG=$2
        _=$OPTARG
        shift ;;
      -i | --icon)
        [ $# -le 1 ] && set -- "$1" required && break
        OPTARG=$2
        _=$OPTARG
        shift ;;
      -c | --category)
        [ $# -le 1 ] && set -- "$1" required && break
        OPTARG=$2
        _=$OPTARG
        shift ;;
      -h | --hint)
        [ $# -le 1 ] && set -- "$1" required && break
        OPTARG=$2
        _=$OPTARG
        shift ;;
      -? | --help)
        usage
        exit 0 ;;
      --) shift
        while [ $# -gt 0 ]; do
          REST="${REST} \"\${$(($OPTIND-$#))}\""
          shift
        done
        break ;;
      [-]?*) set -- "$1" unknown && break ;;
      *) REST="${REST} \"\${$(($OPTIND-$#))}\""
    esac
    shift
  done
  [ $# -eq 0 ] && return 0
  case $2 in
    unknown) echo "unrecognized option '$1'" ;;
    noarg) echo "option '$1' doesn't allow an argument" ;;
    required) echo "option '$1' requires an argument" ;;
    pattern) echo "option '$1' does not match the pattern ($3)" ;;
    *) echo "option '$1' validation error: $2"
  esac >&2
  exit 1
}

parse "$@"
eval set -- "$REST"
pkill herbe
herbe "$@" &