Skip to content

Instantly share code, notes, and snippets.

@nabaco
Created August 24, 2022 22:36
Show Gist options
  • Save nabaco/fa480f568404820fb3164a2d037c3e4e to your computer and use it in GitHub Desktop.
Save nabaco/fa480f568404820fb3164a2d037c3e4e to your computer and use it in GitHub Desktop.
Convert a Dendron vault into an Obsidian vault
#!/usr/bin/bash
set -e
files=$(fd -e md .)
out="obsidian"
# Go over all files and turn the dot structure into diretory hierarchy
for file in $files; do
path=$(basename -s .md "$file" | sed 's#\.#/#g')
dest=$out/$(dirname "$path")
#filename=$(basename $path.md | sed 's#---# - #g' | sed 's#-\([a-zA-z]\)# \1#g')
filename=$(basename $path.md)
# echo "File: $file"
# echo "Path: $path"
# echo "Dest: $dest"
mkdir -p "$dest"
cp "$file" "$dest/$filename"
done
# Move directory notes into the appropriate directory
# Transform hyphens into spaces
dir_files=$(fd -e md . $out)
for file in $dir_files; do
dir=$(basename -s .md "$file")
path=$(dirname "$file")
if [ -d "$path/$dir" ]; then
#echo "Found Directory File for $path/$dir"
mv "$path/$dir.md" "$path/$dir"
else
# grep returns a non-zero status when it doesn't find anything
set +e
rename=$(echo "$dir" | grep -- "-[a-zA-Z]")
set -e
if [ -n "$rename" ]; then
filename=$(echo "$dir" | sed 's#---# - #g' | sed 's#-\([a-zA-z]\)# \1#g')
#echo "$file -> $path/$filename.md"
mv "$file" "$path/$filename.md"
fi
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment