summaryrefslogtreecommitdiffstats
path: root/todo
blob: 318610de2f21d74f08d68a8bb43b0e827755d424 (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
#!/usr/bin/env bash
# email reminder notes using at(1)...

TMPDIR="$(mktemp -d "/tmp/${0##*/}.XXXXXX")"
trap "rm -rf '${TMPDIR}'" EXIT TERM

usage() {
  cat <<EOF
  Options:
  -c     | create job
  -l     | list current jobs
  -p n   | print details for job n
  -h     | print this message

EOF
}

alist() {
  atq | sort -r -k3M -k4
}

aprint() {
  awk -F\" '/@/ { print $2 }' <(at -c "$@")
}

aread() {
  while :; do
    date="$(rlwrap -H "$TMPDIR/date-history" -S "Date and time of message? " -o head -n1)"
    parsed_date="$(date -d "$date")" || continue
    printf "Job will be run at around %s\n" "$parsed_date"

    attime="$(date -d "$date" +%H:%M)"
    atdate="$(date -d "$date" +%D)"
    break;
  done

  read -p "Message body? " message

  at "$attime" "$atdate" << EOF
  printf '%s\n' "$message" | mail -s "REMINDER" bluewind@xinu.at
EOF
}

if (( $# >= 1 )); then
  case "$1" in
    -c) aread
      ;;
    -p) aprint "$2"
      ;;
    -l) alist
      ;;
    -h) usage
      ;;
    *) usage && exit 1
      ;;
  esac
else
  aread
fi

# vim:set ts=2 sts=2 sw=2 et: