aboutsummaryrefslogtreecommitdiff
path: root/collector
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2024-08-20 20:42:35 -0300
committerSilvio Rhatto <rhatto@riseup.net>2024-08-20 20:42:35 -0300
commit3c5c672e47737e6b3342dfeb730ccd8320f2d442 (patch)
treed08d27539f244e640cf1e92ed0f259929fdf5d32 /collector
downloadutils-organization-3c5c672e47737e6b3342dfeb730ccd8320f2d442.tar.gz
utils-organization-3c5c672e47737e6b3342dfeb730ccd8320f2d442.tar.bz2
Initial import
Diffstat (limited to 'collector')
-rwxr-xr-xcollector52
1 files changed, 52 insertions, 0 deletions
diff --git a/collector b/collector
new file mode 100755
index 0000000..387cb02
--- /dev/null
+++ b/collector
@@ -0,0 +1,52 @@
+#!/usr/bin/env bash
+#
+# Collector: add, view, edit a collector file (from GTD/ZTD methodologies).
+#
+# The collector file is a Markdown file with the Task list extension, such as
+# https://docs.gitlab.com/ee/user/markdown.html#task-lists
+#
+
+# Parameters
+BASENAME="`basename $0`"
+ACTION="$1"
+COLLECTOR_NAME="`echo $COLLECTOR_FILE | sed -e "s|$HOME|~|"`"
+
+# Check
+if [ -z "$COLLECTOR_FILE" ]; then
+ # Do not be verbose here, otherwise the "status" command will show an error
+ # message on unconfgirued systems. Maybe that should be controlled by a verbosity flag.
+ #echo "$BASENAME: please export the COLLECTOR_FILE environment variable pointing to your collector markdown file"
+
+ exit 1
+elif [ ! -e "$COLLECTOR_FILE" ]; then
+ echo "$BASENAME: error: file not found: $COLLECTOR_FILE"
+ exit 1
+fi
+
+# Dispatch
+if [ -z "$ACTION" ] || [ "$ACTION" == "view" ]; then
+ cat "$COLLECTOR_FILE"
+elif [ "$ACTION" == "add" ]; then
+ shift
+ echo "* $*" >> "$COLLECTOR_FILE"
+elif [ "$ACTION" == "list" ]; then
+ if grep -q -e "^ *\* " "$COLLECTOR_FILE"; then
+ echo "Collected items at $COLLECTOR_NAME:"
+ echo ""
+ grep -e "^ *\* " "$COLLECTOR_FILE"
+ echo ""
+ fi
+elif [ "$ACTION" == "count" ]; then
+ if grep -q -e "^ *\* " "$COLLECTOR_FILE"; then
+ COUNT="`grep -e "^ *\* " "$COLLECTOR_FILE" | wc -l`"
+ echo "$COUNT collected items at $COLLECTOR_NAME"
+ echo ""
+ fi
+elif [ "$ACTION" == "edit" ]; then
+ if [ ! -z "$EDITOR" ]; then
+ $EDITOR "$COLLECTOR_FILE"
+ else
+ echo "$BASENAME: error: please export the EDITOR environment variable pointing to your editor of choice"
+ exit 1
+ fi
+fi