-
Notifications
You must be signed in to change notification settings - Fork 2
/
whattodo
executable file
·95 lines (75 loc) · 2.4 KB
/
whattodo
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/bin/bash
# SPDX-FileCopyrightText: 2017 - 2024 sudorook <daemon@nullcodon.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.
set -euo pipefail
ROOT="$(dirname "${0}")"
source "${ROOT}"/globals
! check_command find && exit 3
#
# Globals
#
# File name(s) that contain todo lists.
FILES=({TODO,TO-DO}{,.md,.txt,.rtf})
# Extra hard-coded files not in ${projectsdir} (can be left empty).
EXTRAS=({"${HOME}/Desktop/","${HOME}/"}{TODO,TO-DO}{,.md,.txt,.rtf})
# Directories to ignore when searching for lists. Redundant with
# ${ignoreprojectdirs} variable in globals.
IGNORES=("node_modules")
IGNORES+=("${ignoreprojectdirs[@]:-}")
# Base directory to search for to-do lists. Uses the ${projectdir} variable in
# globals by default, with ${HOME} as a fallback if unset.
PROJECTDIR="${projectdir:-${HOME}}"
#
# Functions
#
function print_todo {
local file="${1}"
show_header "${file//${HOME}\//}"
sed '/^# /,/^\s*$/d' "${file}"
echo && echo
}
export -f print_todo
# Search every directory in ${PROJECTDIR} for a file matching one in ${FILES}
# as long as it is not also specified in ${IGNORES}.
function find_todo {
local file
local files
local ignore
local ignores
for file in "${FILES[@]}"; do
files="${files:+${files} -o }-iname ${file}"
done
for ignore in "${IGNORES[@]}"; do
ignores="${ignores:+${ignores} -o }-name ${ignore@Q}"
done
eval "find ${PROJECTDIR@Q} \( ${ignores} \) -prune , \( ${files} \) -exec bash -c 'print_todo \"\${1}\"' bash {} \;"
}
# Print out the to-do lists manually specified in ${EXTRAS}
function find_extra_todo {
local todo
for todo in "${EXTRAS[@]}"; do
if [ -f "${todo}" ]; then
print_todo "${todo}"
fi
done
}
#
# Main
#
[ ${#} -gt 0 ] && show_warning "WARNING: Ignoring parameters ${*}." >&2
find_todo
find_extra_todo