-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodo-prompt
executable file
·38 lines (34 loc) · 1.05 KB
/
todo-prompt
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
#!/bin/sh
# requires todo.sh (todo.txt)
# Uses my OS-agnostic wrapper scripts:
# https://github.com/purarue/dotfiles/tree/master/.local/scripts/cross-platform
# allow me to use this interface for https://github.com/purarue/bookmark.txt
cmd='todo.sh'
if [ "$1" = 'bookmark' ]; then
cmd="$1"
shift
fi
display_cmd="${cmd%%.*}"
prompt_entries() {
ENTRY_CHOICE="$("${cmd}" -p list | head -n -2 | picker -p "[${display_cmd}] Mark which as done? > ")"
if [ -n "${ENTRY_CHOICE}" ]; then
CONFIRM="$(printf 'yes\nno\n' | picker -p "[${display_cmd}] Mark this as done: ${ENTRY_CHOICE}")"
if [ "${CONFIRM}" = "yes" ]; then
ENTRY_NUM="$(echo "${ENTRY_CHOICE}" | cut -d" " -f1)"
# shellcheck disable=SC1010
notify "[${display_cmd}] Completed:" "$("${cmd}" -p do "${ENTRY_NUM}")"
fi
fi
}
# give the user a dialog to add a new entry
add_entry() {
NEW_ENTRY="$(input-dialog "[${display_cmd}] Add > ")"
if [ -n "${NEW_ENTRY}" ]; then
notify "[${display_cmd}] Added:" "$("${cmd}" -p add "${NEW_ENTRY}")"
fi
}
if [ "$1" = "add" ]; then
add_entry
else
prompt_entries
fi