blob: 6905784355b487b68d122505988c99d2f286847e (
about) (
plain) (
blame)
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
|
#!/bin/sh
set -eu
usage() {
cat <<EOF
Usage:
$0 [OPTIONS] [TITLE]
Options:
-h Show this help message
-c Commit directly only with the title, without adding a description
-t TYPE Pick the type of todo to be added (default: task)
-m MESSAGE_TITLE The message (default: FIXME)
EOF
}
uuid() {
# Taken from:
# https://serverfault.com/a/799198
od -xN20 /dev/urandom | \
head -1 | \
awk '{OFS="-"; print $2$3,$4,$5,$6,$7$8$9}'
}
insert_at_line() {
N="$1"
F="$2"
TMP="$(mktemp)"
printf '%s\n\n%s\n\n%s\n' \
"$(head "-n$N" "$F")" \
"$(cat -)" \
"$(tail "-n+$((N+1))" "$F")" \
> "$TMP"
mv "$TMP" "$F"
}
SHORT=false
TYPE=task
MESSAGE=FIXME
while getopts 'hct:m:' flag; do
case "$flag" in
h)
usage
exit
;;
c)
SHORT=true
;;
t)
TYPE="$OPTARG"
;;
m)
MESSAGE="$OPTARG"
;;
*)
;;
esac
done
case "$TYPE" in
task|bug|improvement|question)
;;
*)
echo "Unsupported type: $TYPE"
exit 2
;;
esac
ID="#$TYPE-$(uuid)"
TITLE_LINE="$(printf '## TODO %s {%s}\n- TODO in %s\n' "$MESSAGE" "$ID" "$(date -I)")"
TYPE_LINE="$(grep -in "^# ${TYPE}s$" TODOs.md | cut -d: -f1)"
INSERT_LINE=$((TYPE_LINE + 1))
if [ "$SHORT" = 'true' ] && [ "$MESSAGE" != 'FIXME' ]; then
echo "$TITLE_LINE" | insert_at_line "$INSERT_LINE" TODOs.md
else
printf '%s\n\n---\n\nFIXME\n' "$TITLE_LINE" | vipe | insert_at_line "$INSERT_LINE" TODOs.md
fi
git reset .
git add TODOs.md
git commit -m "TODOs.md: Add $ID"
|