summaryrefslogtreecommitdiff
path: root/bin/extra/routine
blob: e03d471aa3d13f154f52518cc9642855285067c6 (plain)
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
#!/bin/sh

# Dependencies:
# - fzf

routine="$HOME/sync/share/routine.md"
if [ ! -r "$routine" ]; then
    >&2 printf 'No routine file at %s\n' "$routine"
    exit 1
fi

case "$1" in
    "clear") 
        new="$routine.$$"
        sed 's/\[x]/[ ]/' "$routine" > "$new"
        mv "$new" "$routine"
        ;;
    "edit")
        $EDITOR "$routine"
        ;;
    "done")
        grep "^- \[ ]" "$routine" > /dev/null || exit 1
        t="$(grep "^- \[ ]" "$routine" | fzf)"
        [ "$t" ] || exit 2
        new="$routine.$$"
        sed "/${t#- [ }/s/\[ ]/[x]/" "$routine" >> "$new"
        mv "$new" "$routine"
        ;;
    "")
        cat "$routine"
        ;;
esac