]> gitweb.fluxo.info Git - scripts.git/commitdiff
Feat: adds the collector script
authorSilvio Rhatto <rhatto@riseup.net>
Wed, 19 Jul 2023 18:19:19 +0000 (15:19 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Wed, 19 Jul 2023 18:19:19 +0000 (15:19 -0300)
collector [new file with mode: 0755]

diff --git a/collector b/collector
new file mode 100755 (executable)
index 0000000..0e5b50c
--- /dev/null
+++ b/collector
@@ -0,0 +1,37 @@
+#!/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"
+
+# Check
+if [ -z "$COLLECTOR_FILE" ]; then
+  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
+  grep -e "^\* \[ \]" "$COLLECTOR_FILE"
+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