~charles/dotfiles

ref: f2b0d150e08f193450b7f61acd36aafa1aee8e04 dotfiles/overlay/bin/joplin-lstodo -rwxr-xr-x 1.5 KiB
f2b0d150Charles Daniels add lstodo 1 year, 1 month ago
                                                                                
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/sh

set -e
set -u

if [ ! -x "$(which jq)" ] ; then
	echo "no jq in PATH" 1>&2
	exit 1
fi

if [ ! -x "$(which curl)" ] ; then
	echo "no curl in PATH" 1>&2
	exit 1
fi

TOKEN="$(cat "$HOME/.config/joplin-tools/token.txt")"
URL='http://localhost:41184'

if [ -t 1 ] ; then
	GREY='\033[0;37m\e[9m'
	RED='\033[0;31m'
	ORANGE='\033[0;33m'
	NC='\033[0m\e[0m'
else
	GREY=''
	RED=''
	ORANGE=''
	NC=''
fi

curl -s "$URL/notes?token=$TOKEN" | \
	jq -c -r '.[] | select(.is_todo == 1) | [.todo_completed,.title] | @tsv' | \
	( while read -r entry ; do
		complete="$(echo "$entry" | cut -f 1)"
		title="$(echo "$entry" | cut -f2)"
		set +e
		if due="$(echo "$title" | egrep -o '_[0-9]{4}-[0-9]{1,2}-[0-9]{0,2}[ ]+' | sed 's/^_//g')" ; then
			title="$(echo "$title" | sed 's/^_'"$due"'//g')"
		fi
		set -e

		COLOR="NC"
		if [ -z "$due" ] ; then
			due='N/A      '
		elif [ "$(date --date "$due" --iso)" = "$(date --iso)" ] ; then
			COLOR="RED"

		elif [ "$(date --date "$due" +%s)" -lt "$(date --date "7 days" +%s)" ] ; then
			COLOR="ORANGE"
		fi

		if [ "$complete" -gt 0 ] ; then
			due="X        "
			COLOR="GREY"
		fi
		printf "$due\t$title\t$COLOR\n"
	done ) | \
	sort -s | while read -r entry ; do
		COLOR="$(echo "$entry" | cut -f 3)"
		REST="$(echo "$entry" | cut -f 1,2)"
		if [ "$COLOR" = "NC" ] ; then
			COLOR="$NC"
		elif [ "$COLOR" = "GREY" ] ; then
			COLOR="$GREY"
		elif [ "$COLOR" = "RED" ] ; then
			COLOR="$RED"
		elif [ "$COLOR" = "ORANGE" ] ; then
			COLOR="$ORANGE"
		else
			COLOR=""
		fi
		printf "$COLOR$REST$NC\n"
	done