Last active
July 8, 2022 11:26
-
-
Save t-buss/e7e16b1fc324c47b1900a0f83ea5c550 to your computer and use it in GitHub Desktop.
Create entries to daily log, new Zettelkasten notes in Obsidian or TODOs in a Obsidian Kanban board with Rofi
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 | |
set -o pipefail | |
function log() { | |
local CONTENT | |
CONTENT=$1 | |
DAILY_NOTE_FILENAME=`date +"%Y_%m_%d"`.md | |
if [[ ! -f $HOME/Repos/obsidian/Reboot/DailyNotes/$DAILY_NOTE_FILENAME ]]; then | |
cp $HOME/Repos/obsidian/Reboot/Templates/DailyNote.md \ | |
$HOME/Repos/obsidian/Reboot/DailyNotes/$DAILY_NOTE_FILENAME | |
fi | |
printf -- "- %b %b\n" "$TIMESTAMP" "$CONTENT" >> $HOME/Repos/obsidian/Reboot/DailyNotes/$DAILY_NOTE_FILENAME | |
if [[ "${CONTENT,,}" =~ ^(lunch break) ]]; then | |
printf -- "---\n" >> $HOME/Repos/obsidian/Reboot/DailyNotes/$DAILY_NOTE_FILENAME | |
fi | |
} | |
TIMESTAMP=`date +%H:%M` | |
CONTENT=`echo -e "Good Morning\nDaily\nLunch Break\nBack from lunch\nFeierabend\nStunden eingetragen" | rofi -dmenu -l 6 -p ">>>" -font "JetBrains Mono NF 13"` | |
if [[ -z "$CONTENT" ]]; then | |
exit 1 | |
fi | |
if [[ "$CONTENT" =~ ^(todo|TODO) ]]; then | |
CONTENT=$(echo $CONTENT | sed 's/^todo //gi') | |
LINE=$(printf -- '- [ ] %b\n' "$CONTENT") | |
sed -ibak --follow-symlinks "/^## Todo/a $LINE" $HOME/Repos/obsidian/Reboot/Projects/current.md | |
rm $HOME/Repos/obsidian/Reboot/Projects/*.mdbak | |
log "Created Todo: $CONTENT" | |
exit 0 | |
fi | |
if [[ "$CONTENT" =~ ^(doing ) ]]; then | |
CONTENT=$(echo $CONTENT | sed 's/^doing //gi') | |
LINE=$(printf -- '- [ ] %b\n' "$CONTENT") | |
sed -ibak --follow-symlinks "/^## Doing/a $LINE" $HOME/Repos/obsidian/Reboot/Projects/current.md | |
rm $HOME/Repos/obsidian/Reboot/Projects/*.mdbak | |
log "Created Doing: $CONTENT" | |
exit 0 | |
fi | |
if [[ "$CONTENT" =~ ^(waiting ) ]]; then | |
CONTENT=$(echo $CONTENT | sed 's/^waiting //gi') | |
LINE=$(printf -- '- [ ] %b\n' "$CONTENT") | |
sed -ibak --follow-symlinks "/^## Waiting/a $LINE" $HOME/Repos/obsidian/Reboot/Projects/current.md | |
rm $HOME/Repos/obsidian/Reboot/Projects/*.mdbak | |
log "Created Waiting: $CONTENT" | |
exit 0 | |
fi | |
if [[ "$CONTENT" =~ ^(done ) ]]; then | |
CONTENT=$(echo $CONTENT | sed 's/^done //gi') | |
LINE=$(printf -- '- [ ] %b\n' "$CONTENT") | |
sed -ibak --follow-symlinks "/^## Done/a $LINE" $HOME/Repos/obsidian/Reboot/Projects/current.md | |
rm $HOME/Repos/obsidian/Reboot/Projects/*.mdbak | |
log "Created Done: $CONTENT" | |
exit 0 | |
fi | |
URL_REGEX='https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)' | |
if [[ "$CONTENT" =~ ^(z ) ]]; then | |
CONTENT=$(echo $CONTENT | sed 's/^z //gi') | |
LAST_WORD=$(echo $CONTENT | awk 'NF{ print $NF }') | |
if [[ "$LAST_WORD" =~ $URL_REGEX ]]; then | |
CONTENT=$(echo $CONTENT | awk '{ $NF="" } { print }' | sed 's/ $//') | |
fi | |
cp $HOME/Repos/obsidian/Reboot/Templates/ZettelkastenTemplate.md $HOME/Repos/obsidian/Reboot/Zettelkasten/"$CONTENT".md | |
sed -ibak "s/^# $/# $CONTENT/g" $HOME/Repos/obsidian/Reboot/Zettelkasten/"$CONTENT".md | |
rm $HOME/Repos/obsidian/Reboot/Zettelkasten/*.mdbak | |
if [[ "$LAST_WORD" =~ $URL_REGEX ]]; then | |
echo "Regex works" | |
echo $CONTENT | |
echo $LAST_WORD | |
sed -ibak "s|^source: $|source: $LAST_WORD|g" $HOME/Repos/obsidian/Reboot/Zettelkasten/"$CONTENT".md | |
rm $HOME/Repos/obsidian/Reboot/Zettelkasten/*.mdbak | |
fi | |
log "Created ZK note: [[$CONTENT]]" | |
exit 0 | |
fi | |
log "$CONTENT" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment