summaryrefslogtreecommitdiff
path: root/bin/extra
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2024-10-08 14:54:50 +0200
committerRaymaekers Luca <raymaekers.luca@gmail.com>2024-10-08 14:54:50 +0200
commite73e19e82a893bacd3c1da87835bc066aa69bb23 (patch)
tree3118beecdcda549b16b7eea0c628ae9c517f18e2 /bin/extra
parent7a91a55b79f828017b38c9f0af479b25c89bf6a9 (diff)
checkpoint
Diffstat (limited to 'bin/extra')
-rwxr-xr-xbin/extra/notes_index40
-rwxr-xr-xbin/extra/routine32
2 files changed, 72 insertions, 0 deletions
diff --git a/bin/extra/notes_index b/bin/extra/notes_index
new file mode 100755
index 0000000..9ccb3b2
--- /dev/null
+++ b/bin/extra/notes_index
@@ -0,0 +1,40 @@
+#!/bin/sh
+
+NOTES="$HOME"/notes
+
+if ! [ -d "$NOTES" ]; then
+ >&2 printf 'No notes directory.\n'
+ exit 1
+fi
+
+cd "$NOTES"
+
+find . -type d | while read -r d
+do
+ cd "$d"
+ printf '# Notes\n' > index.md
+ find . \
+ -maxdepth 1 \
+ -type f \
+ -name '*.md' \
+ -not \
+ -name 'index.md' \
+ -printf '%f ' \
+ -exec grep '^# ' -m1 {} \; |
+ sed 's/\(.\+\.md\) # \(.\+\)/- [\2](\1)/' |
+ sort -t '[' -k 2 >> index.md
+
+ if [ "$(find . -mindepth 2 -maxdepth 2 -type f -name '*.md' | wc -l)" -gt 0 ]
+ then
+ printf '# Dirs\n' >> index.md
+ find . \
+ -mindepth 1 \
+ -maxdepth 1 \
+ -type d \
+ -not -name '.*'\
+ -printf '- [%f](%f/index.md)\n' |
+ sort -t '[' -k 2 >> index.md
+ fi
+
+ cd - > /dev/null
+done
diff --git a/bin/extra/routine b/bin/extra/routine
new file mode 100755
index 0000000..e03d471
--- /dev/null
+++ b/bin/extra/routine
@@ -0,0 +1,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