~yerinalexey/dotfiles

ref: 144a38b0aa0a39003633d53b77fe4e3ca29c054b dotfiles/scripts/todo -rwxr-xr-x 1.1 KiB
144a38b0Alexey Yerin river,update-volume: fix old wob crashes 5 months 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
#!/bin/sh

# Manage To Do lists
# Usage:
#   todo [-a] [-g] [name]
#
# Running `todo` without a name will edit a project-specific list
# ~/todo/<project>.todo, where <project> is derived from the last path
# segment or current working directory. Otherwise, it opens a global
# list ~/todo/todo
#
# Using a name argument forces to edit project-specific list
# ~/todo/name.todo
#
# Using -a option will concatenate all lists and display them using
# $PAGER.
#
# Using -g option will force editing the global list, ignoing
# project-specific ones.

TODO_HOME="$HOME"/todo

edit() {
	"$EDITOR" +'set ft=plain' "$1"
}

global=0
all=0
while getopts ga opt; do
	case "$opt" in
		a) all=1 ;;
		g) global=1 ;;
	esac
done
shift $((OPTIND - 1))

if [ "$all" = "1" ]; then
	cat "$TODO_HOME"/todo "$TODO_HOME"/*.todo | "${PAGER:-less}"
elif [ "$global" = "1" ]; then
	edit "$TODO_HOME"/todo
elif [ -z "$1" ]; then
	# Use project-specific list and fall back to global if it doesn't
	# exist
	proj="$(basename "$(pwd)")"
	file="$TODO_HOME"/"$proj".todo

	if [ -f "$file" ]; then
		edit "$file"
	else
		edit "$TODO_HOME"/todo
	fi
else
	edit "$TODO_HOME"/"$1".todo
fi