Last active
December 30, 2022 14:25
-
-
Save dsas/46f3364be61bcdddd40febc9772e6012 to your computer and use it in GitHub Desktop.
Rename Roam daily files to Obsidian daily files
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 -euo pipefail | |
IFS=$'\n\t' | |
########### | |
# | |
# Adapted from a script by @pmbauer: | |
# https://forum.obsidian.md/t/converting-roam-daily-notes-to-yyyy-mm-dd-format-with-backlinks/13770 | |
# Changes are: | |
# Use gsed because osx | |
# Add a prefix constant to allow more flexibility over where the files are kept | |
# Change delimiter of sed expression so prefix can include forward slashes | |
# | |
# To run on OSX: | |
# 0. Ensure you have coreutils and gnu sed installed via brew | |
# 1. Place in the root of your vault | |
# 2. PATH=/usr/local/opt/coreutils/libexec/gnubin:$PAT *,\ 202[012].md | ./convert_daily_notes | |
# | |
########### | |
# Set to e.g. Dailies/ to move the files to the Dailies directory | |
PREFIX='' | |
roam_date_to_obsidian() { | |
date --date="$(echo "${*}" | gsed 's/th//;s/nd//;s/rd//;s/1st/1/')" '+%Y-%m-%d' | |
} | |
while IFS= read -r line; do | |
roam_daily_note=${line/%.md/} | |
obsidian_daily_note=$(roam_date_to_obsidian ${roam_daily_note}) | |
cat "${roam_daily_note}.md" >> ${PREFIX}${obsidian_daily_note}.md | |
# update links | |
gsed -i "s#\[\[${roam_daily_note}]]#[[${PREFIX}${obsidian_daily_note}]]#g" *.md */*.md || true | |
# give it a relevant timestamp | |
touch -d ${obsidian_daily_note} ${PREFIX}${obsidian_daily_note}.md | |
rm "${roam_daily_note}.md" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment