Skip to content

Instantly share code, notes, and snippets.

@chusiang
Created September 4, 2023 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chusiang/a9c8fde8990b761d2b7a627a54c96dd3 to your computer and use it in GitHub Desktop.
Save chusiang/a9c8fde8990b761d2b7a627a54c96dd3 to your computer and use it in GitHub Desktop.
Migrate diary from yyyy-mm-dd.md to multi-sub directory architecture for "mattn/calendar-vim" plugin.
#!/bin/bash
# =============================================================================
# Author: Chu-Siang Lai / chusiang (at) drx.tw
# Blog: http://note.drx.tw
# Filename: migrate-diary-to-sub-dir.sh
# Modified: 2023-09-04 15:52
# Description: Migrate diary from vimwiki/obsidian format to multi-sub
# directory architecture for "mattn/calendar-vim" plugin, and
# only review/edit via Vim.
# Reference: https://github.com/chusiang/vimrc/commit/faca1de7e49f9a51cba3805d4ba3b2fc8a449909
# =============================================================================
function gen_yyyy_mm_dir() {
for X in {01..12}; do
mkdir -p "2017/${X}"
mkdir -p "2018/${X}"
mkdir -p "2019/${X}"
mkdir -p "2020/${X}"
mkdir -p "2021/${X}"
mkdir -p "2022/${X}"
done
}
function move_yyyy_mm() {
for YYYY in {2017..2021}; do
for MM in {01..12}; do
for DD in {01..31}; do
mv ${YYYY}-${MM}-${DD}.md ${YYYY}/${MM}/
done
cd ${YYYY}/${MM}/
rename "s/${YYYY}-${MM}-//" *.md
cd ../..
done
done
}
# - main ----------------------------------------------------------------------
gen_yyyy_mm_dir
move_yyyy_mm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment