summaryrefslogtreecommitdiff
path: root/t
blob: dc40e6daf2fb25fc4597069482ad18385c187e0c (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
#!/bin/sh

unset KILL SPAWN

MODE="t"

while getopts "-tr" o; do case "${o}" in
  t) MODE="t" ;;
  r) MODE="r" ;;
  -) break ;;
esac done

SPAWN="$(echo "$@" | sed 's/^.*-[-tr] //')"
KILL="$(echo $SPAWN | cut -d' ' -f1)"

[ -z "${MODE}" -o -z "$SPAWN" ] && exit
case "${MODE}" in
  t)
    if pgrep -x "$KILL"; then
      killall "$KILL" 2>&1 >/dev/null
    else
      $SPAWN &
    fi
    ;;
  r)
    killall "$KILL" 2>&1 >/dev/null
    sleep 0.1
    $SPAWN &
    ;;
esac