Created
March 14, 2021 11:27
-
-
Save reactorcoremeltdown/87d9cba2505bd2d38a2039ac14be0822 to your computer and use it in GitHub Desktop.
Zettelkasten automation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -e | |
## Using line feed as a delimeter when cycling through tags | |
IFS=$'\n' | |
## Starting an index page here | |
echo -e "## Zettelkasten Index\n\n" > zettelkasten.md | |
## Beginning of a "tag cloud", we're not adding a line feed here | |
echo -n "#### " >> zettelkasten.md | |
## Cycling through tags. This line is shitty & probably needs rewriting | |
## But at least it works both on Mac and Linux! | |
for tag in $(grep -hri '^##### Tags' zettelkasten/ | sed 's|##### Tags: ||g;s|, |\n|g;s|\[||g;s|\]||g'| cut -f 1 -d '(' | sort -u); do | |
## echo-ing every tag without LF into a "tag cloud" | |
echo -n "[${tag}](./zettelkasten/catalog/$(echo ${tag} | sed 's|\ |%20|g').md) ••• " >> zettelkasten.md | |
## Building an index of notes for each tag, using relative paths everywhere | |
## Gitea can take care of rendering links | |
echo -e "#### ${tag} | [Index](../../zettelkasten.md#zettelkasten-index)" > zettelkasten/catalog/${tag}.md | |
FNAMES=$(grep -ri '^##### Tags' zettelkasten | grep "${tag}" | cut -f 1 -d ':' | sort) | |
for FNAME in ${FNAMES}; do | |
echo "+ [$(basename ${FNAME})](../../${FNAME})" >> zettelkasten/catalog/${tag}.md | |
done | |
done | |
## Adding all generated pages into upcoming commit | |
## We're done here | |
git add zettelkasten.md | |
git add zettelkasten/catalog/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 14 Mar 2021 | [Index](./zettelkasten.md#zettelkasten-index) | |
##### Tags: [[blog]], [[music]], [[writing]], [[tech]] | |
This is a sample note that gets "compiled" into a zettelkasten page | |
Motorola ROKR G3, an attempt to return music phones to life[^1] | |
+ Boot screen | |
+ Navigation key buttons (music player + radio) | |
+ Wallpapers | |
+ /etc/mixer_paths.xml for boosting headphone volume | |
+ Vanilla Music + Replay gain | |
+ Builtin FM radio | |
+ Last.FM scrobbler | |
+ Syncthing | |
+ Power button double click shortcut | |
+ Additional software (AntennaPod, VLC) | |
+ Panasonic earpieces with play/pause button | |
+ Music itself | |
[^1]: [link](./2021-02-22_10-51-16.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
## Put this shortcut somewhere inside ${PATH} | |
set -e | |
## Each filename gets compiled from current date | |
COMMIT_MESSAGE="Added some lines" | |
FILENAME="$(date "+%Y-%m-%d_%H-%M-%S").md" | |
## My repo path, change it to whatever you like | |
cd ${HOME}/dev/mood-tracker/zettelkasten/ \ | |
## Before adding new notes we need to make sure there won't be merge conflicts | |
&& git pull \ | |
## Checking if a note exists already (highly unlikely, but still) | |
## and creating a new one out of a template otherwise | |
&& test -f ${FILENAME} \ | |
|| { date '+## %d %b %Y | [Index](./zettelkasten.md#zettelkasten-index)%n%n##### Tags: %n%n' > ${FILENAME} && COMMIT_MESSAGE="New idea"; } \ | |
## Editing a file + jumping to the last line | |
&& vim + ${FILENAME} \ | |
## Cross-platform sed pipeline for replacing obsidian-like tags with actual links to tag index pages | |
&& sed -i.bak 's|\[\[\([a-zA-Z0-9]*\)\]\]|\[\1\](./catalog/\1\.md)|g' ${FILENAME} \ | |
## We don't need a backup file | |
&& rm -f "${FILENAME}.bak" \ | |
## Adding, committing, and pushing | |
&& git add ${FILENAME} \ | |
&& git commit -m "${COMMIT_MESSAGE}" \ | |
&& git push origin master \ | |
&& cd - |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment