Skip to content

Instantly share code, notes, and snippets.

@jasonwryan
Created September 6, 2014 21:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasonwryan/54fead5ad2b0c3b82621 to your computer and use it in GitHub Desktop.
Save jasonwryan/54fead5ad2b0c3b82621 to your computer and use it in GitHub Desktop.
Florian Pritz's changes to reminder script
todo | 43 ++++++++++++++++++++++++-------------------
1 file changed, 24 insertions(+), 19 deletions(-)
diff --git a/todo b/todo
old mode 100644
new mode 100755
index 2169665..78dc94f
--- a/todo
+++ b/todo
@@ -1,6 +1,9 @@
#!/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:
@@ -17,40 +20,42 @@ alist() {
}
aprint() {
- awk -F\" '/gmail/ { print $2 }' <(at -c "$@")
+ awk -F\" '/@/ { print $2 }' <(at -c "$@")
}
aread() {
- read -p "Time of message? [HH:MM] " attime
- read -p "Date of message? [DD.MM.YY] " atdate
- read -p "Message body? " message
+ 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 %s\n" "$parsed_date"
- timexp='^[0-9]{2}:[0-9]{2}'
- datexp='^[0-9]{2}.[0-9]{2}.[0-9]{2}'
+ attime="$(date -d "$date" +%H:%M)"
+ atdate="$(date -d "$date" +%D)"
+ break;
+ done
+
+ read -p "Message body? " message
- if [[ $attime =~ $timexp && $atdate =~ $datexp ]]; then
- at "$attime" "$atdate" << EOF
- printf '%s\n' "$message" | mutt -s "REMINDER" jasonwryan@gmail.com
+ at "$attime" "$atdate" << EOF
+ printf '%s\n' "$message" | mail -s "REMINDER" bluewind@xinu.at
EOF
- else
- printf '%s\n' "Incorrectly formatted values, bailing..." && exit 1
- fi
}
if (( $# >= 1 )); then
case "$1" in
-c) aread
- ;;
+ ;;
-p) aprint "$2"
- ;;
+ ;;
-l) alist
- ;;
+ ;;
-h) usage
- ;;
- *) usage && exit 1
- ;;
+ ;;
+ *) usage && exit 1
+ ;;
esac
-else usage && exit 1
+else
+ aread
fi
# vim:set ts=2 sts=2 sw=2 et:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment