aboutsummaryrefslogtreecommitdiff
path: root/collector
blob: aba470e1cd8f8ec153d23c4f890c4ab1ebf17f0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/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
  if grep -q -e "^ *\* " "$COLLECTOR_FILE"; then
    echo "Collected items at $COLLECTOR_FILE:"
    echo ""
    grep -e "^ *\* " "$COLLECTOR_FILE"
    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