-
Notifications
You must be signed in to change notification settings - Fork 0
/
todo_watch
executable file
·55 lines (44 loc) · 1.35 KB
/
todo_watch
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
#!/bin/sh
# shellcheck disable=SC1090
# TODO: replace with python or something else
# XXX: avoid exiting for bogus reasons?
# set -e
# set -x
set -u
if [ "$#" -eq 0 ]; then
echo "Usage: $0 TODO_TXT_COMMAND MIN_PRIORITY [SEARCH_TERMS]"
exit 1
fi
. "$ZDOTDIR"/11_locals.zsh
tcmd="$1"
shift
if [ "${TODOWATCH_LASTPRIO:-nope}" = "nope" ]; then
TODOWATCH_LASTPRIO="$1"
shift
fi
twatch(){
while true; do
# probably useless, if fs is ok
sync "$TODO_GLOBAL"/*
# still got the bug with 0.4 under heavy load with only one sync
sleep 0.4
clear
sync "$TODO_GLOBAL"/*
if [ "${TODOWATCH_LEAVEWHENDONE:-}" = "y" ]; then
# shellcheck disable=SC2068
if ! ($tcmd -p lsp A-"$TODOWATCH_LASTPRIO" $@ | head -n -2 | grep -E -v '^[[:digit:]]{2} x ' ) > /dev/null ; then
echo "No items anymore, exiting..."
sleep 2
# return 0
fi
fi
# don't show done tasks
# show tasks with no priorities
t ls | grep -P '^[[:digit:]]{1,3} [[:digit:]]{4}-[[:digit:]]{2}-[[:digit:]]{2}'
# shellcheck disable=SC2068
$tcmd lsp A-"$TODOWATCH_LASTPRIO" $@ | grep -v '[[:digit:]][[:digit:]] x'
# timeout to refresh periodically (useful when screen size changes), --foreground to kill via CTRL-C faster.
timeout --foreground 120 inotifywait -qq -e create,modify "$TODO_GLOBAL"/* > /dev/null
done
}
twatch "$@"