Skip to content

Instantly share code, notes, and snippets.

@yue82
Created May 19, 2018 09:41
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 yue82/50029ac5f9ce1e7bfe926a6d0defff07 to your computer and use it in GitHub Desktop.
Save yue82/50029ac5f9ce1e7bfe926a6d0defff07 to your computer and use it in GitHub Desktop.
generate weekly memo
#! /bin/bash
year=`date +%Y`
month=`date +%m`
day=`date +%d`
weekday=5
next_weekstartday=3
if [ -z $1 ]; then
before_offset=0
after_offset=0
else
before_offset=$1
weekday=$((weekday-before_offset))
if [ -z $2 ]; then
after_offset=0
else
after_offset=$2
weekday=$((weekday-after_offset))
fi
fi
weekstart=`date +%m%d -d "$((next_weekstartday + before_offset)) days"`
weekstart_year=`date +%Y -d "$((next_weekstartday + before_offset)) days"`
weekstart_month=`date +%m -d "$((next_weekstartday + before_offset)) days"`
weekend=`date +%m%d -d "$((next_weekstartday + before_offset - after_offset + weekday - 1)) days"`
if [ ! -e ~/memos/$weekstart_year"_"$weekstart_month ]; then
mkdir ~/memos/$weekstart_year"_"$weekstart_month
fi
cp -n ~/memos/template_weekly.md ~/memos/$weekstart_year"_"$weekstart_month/$weekstart_year"_"$weekstart"-"$weekend".md"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment