diff options
author | ensa <psii@riseup.net> | 2020-05-26 23:49:07 -0700 |
---|---|---|
committer | ensa <psii@riseup.net> | 2020-05-26 23:49:07 -0700 |
commit | 24b546aa76dad714036e18dd6204c7688056c4a7 (patch) | |
tree | ba8401b345602de96a3506322ae348ee6bd07f89 | |
download | todo-24b546aa76dad714036e18dd6204c7688056c4a7.tar.gz |
initial commit
all the relevant info is present in README, TODO, LICENSE, and todo.
-rw-r--r-- | LICENSE | 6 | ||||
-rw-r--r-- | README | 22 | ||||
-rw-r--r-- | TODO | 3 | ||||
-rwxr-xr-x | todo | 70 |
4 files changed, 101 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..12aca95 --- /dev/null +++ b/LICENSE @@ -0,0 +1,6 @@ +ISC License: +Copyright (c) 2020, ensa + +Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. diff --git a/README b/README new file mode 100644 index 0000000..c8da6ab --- /dev/null +++ b/README @@ -0,0 +1,22 @@ +todo: a todo list manager +requires standard POSIX utils and mktemp + +install: +copy to anywhere in your $PATH + +relevant variables: + $EDITOR (preferred editor, uses vi if blank) + $TODO (path to todo file, uses $HOME/todo if blank) + +options: +[no args] shows todo file with numbered lines +-e edits $TODO in $EDITOR +-x shows completed tasks +-n num operate on line num +-a string add string to todo +-d [num] delete line num + + +trick: +todo -n 10 -a 'string' + will place string at line ten, pushing each line after it down by one diff --git a/TODO b/TODO new file mode 100644 index 0000000..f8adbc4 --- /dev/null +++ b/TODO @@ -0,0 +1,3 @@ +implement mktemp(1) within the script file + mktemp is not POSIX, though it's common + alternatively, figure out inplace editing that's POSIX compliant diff --git a/todo b/todo new file mode 100755 index 0000000..7243f77 --- /dev/null +++ b/todo @@ -0,0 +1,70 @@ +#!/bin/sh + +#preset vars +EDITOR=${EDITOR:-vi} +TODO=${TODO:-$HOME/todo} +#empty opt vars +ADD="" +DELETE="" +NUM="" +CHANGE="" +ARCHIVE="" + +ug_err() +{ + echo "${1}" 1>&2 && return "${2:-1}" +} +usage() +{ + ug_err "usage: ${0##*/} [[-e | -x ] | [-n num] [-a message | -d [num]] + -e edit todo in $EDITOR + -x show completed tasks + -n num operate on line num + -a string add string to todo + -d [num] delete line num" +} +while getopts a:d:en:x arg; do + case ${arg} in + a) ADD=${OPTARG};; + d) DELETE=true + NUM=${OPTARG};; + e) CHANGE=true;; + n) NUM=${OPTARG};; + x) ARCHIVE=true;; + *) usage;; + esac +done +#satisfies -a +if [ -n "$ADD" ]; then + if [ -n "$NUM" ]; then + TMP=$(mktemp) + sed "${NUM}i\\ +$ADD +" < "$TODO" > "$TMP" && mv "$TMP" "$TODO" + else + printf '%s\n' "$ADD" >> "$TODO" + fi + exit +fi +#satisfies -d +if [ -n "$DELETE" ]; then + TMP=$(mktemp) + date +"%F %T - $(sed -n "${NUM}p" "$TODO")" >> "${TODO}.complete" + sed "${NUM}D" < "$TODO" > "$TMP" && mv "$TMP" "$TODO" + exit +fi +#satisfies -e +if [ -n "$CHANGE" ]; then + "$EDITOR" "$TODO" + exit +fi +#satisfies -x and no flags +if [ -z "$ADD" ] && [ -z "$DELETE" ] && [ -z "$CHANGE" ]; then +if [ -n "$ARCHIVE" ]; then + ! [ -e "${TODO}.complete" ] && touch "${TODO}.complete" + cat < "${TODO}.complete" +elif [ -z "$*" ]; then + nl "${TODO}" +fi +exit +fi |