Implement the `due' subcommand. - justdoit - Simpler (but with not all the features) reimplementation todo.txt CLI
(HTM) hg clone https://bitbucket.org/iamleot/justdoit
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
---
(DIR) changeset 456b3b47c084c022a46aba8586d26467bf3f3d3e
(DIR) parent 49ae66e3118e2bfe225fdc16a3613b2470ec1925
(HTM) Author: Leonardo Taccari <iamleot@gmail.com>
Date: Sun, 19 Aug 2018 00:22:21
Implement the `due' subcommand.
Permit to have the `due:%Y-%m-%d' keyword in task and filter them with the due
that accept number. of days and possible further pattern.
Diffstat:
t.sh | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 52 insertions(+), 1 deletions(-)
---
diff -r 49ae66e3118e -r 456b3b47c084 t.sh
--- a/t.sh Sat Aug 18 23:44:34 2018 +0200
+++ b/t.sh Sun Aug 19 00:22:21 2018 +0200
@@ -43,7 +43,7 @@
usage()
{
- echo "usage: t add|done|edit|help|list|listall"
+ echo "usage: t add|done|due|edit|help|list|listall"
exit 1
}
@@ -64,6 +64,11 @@
echo "Mark an item \`item' of todo.txt file as done, moving it in done.txt"
echo "and removing it from todo.txt"
echo
+ echo "due days [pattern]"
+ echo "List all task due next number of days - and all the expired"
+ echo "ones - that matches pattern (or all of them if no pattern is"
+ echo "provided)"
+ echo
echo "edit"
echo "Open the todo.txt with the \${EDITOR}"
echo
@@ -222,6 +227,47 @@
#
+# Filter all due: key-values task of the next n. days and all "expired" ones.
+#
+due()
+{
+ days="$1"
+
+ awk -v days="${days}" '
+ function date_to_seconds(date) {
+ "date -d " date " +%s" | getline
+ return $0
+ }
+
+ function seconds_to_date(seconds) {
+ "date -r " seconds " +%Y%m%d" | getline
+ return $0
+ }
+
+ BEGIN {
+ n_days = int(days)
+ n_seconds = date_to_seconds(strftime("%Y%m%d")) + \
+ (n_days * 60 * 60 * 24)
+ }
+
+ match($0, /due:[0-9]+-[0-9]+-[0-9]+/) {
+ # XXX: We mess up with getline in date_to_seconds()
+ # XXX: so backup the current line.
+ s = $0
+
+ # Delete "due:" and convert the date in %Y%m%d format
+ due_date = substr(s, RSTART + 4, RLENGTH - 4)
+ gsub(/\-/, "", due_date)
+
+ if (n_seconds >= date_to_seconds(due_date)) {
+ print s
+ }
+ }
+ '
+}
+
+
+#
# t, a todo.sh clone in POSIX shell script
#
main()
@@ -237,6 +283,11 @@
item=$2
mark_done "${todo_file}" "${done_file}" "${item}"
;;
+ due)
+ days=$2
+ search=$3
+ list "${todo_file}" "${search}" | due "${days}"
+ ;;
e|ed|edit)
${EDITOR} "${todo_file}"
;;