From 82d07da3add2393c53d20e41e8aba383f058858f Mon Sep 17 00:00:00 2001 From: Raymaekers Luca Date: Sat, 1 Jun 2024 13:32:36 +0200 Subject: checkpoint --- bin/menuscripts/td | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100755 bin/menuscripts/td (limited to 'bin/menuscripts/td') diff --git a/bin/menuscripts/td b/bin/menuscripts/td new file mode 100755 index 0000000..e905d9b --- /dev/null +++ b/bin/menuscripts/td @@ -0,0 +1,65 @@ +#!/bin/sh + +todo="$HOME/docs/filios"/todo + +die() { >&2 printf '%s\n' "$*"; exit 1; } +usage() +{ + cat <&2 printf 'Wrong usage!\n'; usage; } + +list_todos() { + [ ! -r "$todo" ] && die "No to-do's." + [ "$(wc -l < "$todo")" -eq 0 ] && die "No to-do's." + awk '{print NR ": " $0}' "$todo" +} + +# shellcheck disable=SC2142 + +### MAIN + +# Arguments without an option +case "$1" in + c*) rm -f "$todo"; >&2 printf 'Cleared.\n' ;; + h*) usage ;; + e*) $EDITOR "$todo" ;; + "") list_todos ;; + *) false ;; +esac && exit + + +arg="$1" +shift +[ "$1" ] || wrong_usage + +case "$arg" in + n*) + printf '%s\n' "$*" >> "$todo" + list_todos ;; + + d*) + sed -i -n "$1!p" "$todo" + list_todos ;; + g*) list_todos | grep "$*" ;; + + m*) + [ "$2" ] || wrong_usage + line="$(list_todos | sed "/^$1:/!d;s/^$1: //")" + sed -i "${1}d;${2}i${line}" "$todo" + list_todos ;; + + *) wrong_usage ;; +esac -- cgit v1.2.3