Raw
#!/bin/sh
# requires todo.sh (todo.txt)
# Uses my OS-agnostic wrapper scripts:
# https://github.com/seanbreckenridge/dotfiles/tree/master/.local/scripts/cross-platform

# allow me to use this interface for https://github.com/seanbreckenridge/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