Initial commit - 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 1e019693d15ae56096f7b735cc272d6a1cbc3970
(HTM) Author: Leonardo Taccari <iamleot@gmail.com>
Date: Sat, 18 Aug 2018 01:30:53
Initial commit
Diffstat:
t.sh | 155 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 155 insertions(+), 0 deletions(-)
---
diff -r 000000000000 -r 1e019693d15a t.sh
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/t.sh Sat Aug 18 01:30:53 2018 +0200
@@ -0,0 +1,155 @@
+#!/bin/sh
+
+#
+# Copyright (c) 2018 Leonardo Taccari
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
+# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+config_file=${T_CONFIG_FILE:=${HOME}/.config/t/t.conf}
+
+if [ -f "${config_file}" ]; then
+ . "${config_file}"
+fi
+
+todo_file=${T_TODO_FILE:=${HOME}/.config/t/todo.txt}
+done_file=${T_DONE_FILE:=${HOME}/.config/t/done.txt}
+
+
+#
+# Print usage message and exit
+#
+usage()
+{
+
+ echo "usage: t add|done|edit|help|list"
+
+ exit 1
+}
+
+
+#
+# Add an entry at the end of a todo.txt file
+#
+add()
+{
+ file=$1
+ entry=$2
+
+ echo "${entry}" >> "${file}"
+}
+
+
+#
+# Mark an entry item as done, adding it to the done.txt file and removing it
+# from the todo.txt file.
+#
+mark_done()
+{
+ tfile=$1
+ dfile=$2
+ item=$(($3))
+
+ if [ ${item} -ge 1 ] && [ ${item} -le $(wc -l < "${tfile}") ]; then
+ {
+ printf "x %s " "$(date +%Y-%m-%d)";
+ sed -n "${item}p" "${tfile}";
+ } >> "${dfile}"
+ sed -i.bak "${item}d" "${tfile}"
+ fi
+}
+
+
+#
+# List, show the contents of a todo.txt file
+#
+list()
+{
+ file=$1
+ search=$2
+
+ cat "${file}" | prettify | grep -F -- "${search}"
+}
+
+
+#
+# Prettify the output of a todo.txt
+#
+prettify()
+{
+
+ awk '
+ function bold(s) {
+ return sprintf("\033[1m%s\033[0m", s);
+ }
+
+ function underline(s) {
+ return sprintf("\033[4m%s\033[0m", s);
+ }
+
+ {
+ # bold all the tags
+ gsub(/@[^ ]+/, "\033[1m&\033[0m")
+
+ printf("%12s %s\n", underline(NR), $0)
+ }
+ '
+}
+
+
+#
+# t, a todo.sh clone in POSIX shell script
+#
+main()
+{
+ subcommand=$1
+
+ case $subcommand in
+ a|add)
+ entry=$2
+ add "${todo_file}" "${entry}"
+ ;;
+ d|do|done)
+ item=$2
+ mark_done "${todo_file}" "${done_file}" "${item}"
+ ;;
+ e|ed|edit)
+ ${EDITOR} "${todo_file}"
+ ;;
+ h|help)
+ usage
+ ;;
+ l|ls|list)
+ search=$2
+ list "${todo_file}" "${search}"
+ ;;
+ *)
+ usage
+ ;;
+ esac
+
+ exit 0
+}
+
+main "$@"