Skip to content

Instantly share code, notes, and snippets.

@pmbauer
Last active July 22, 2020 02:15
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pmbauer/9285d6a6c72fc86d9300f28042642ca6 to your computer and use it in GitHub Desktop.
Save pmbauer/9285d6a6c72fc86d9300f28042642ca6 to your computer and use it in GitHub Desktop.
roam weekly plan
#/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
roam_date() {
date -d "${*}" '+%B %eXX, %Y' \
| sed -e 's/11XX/11th/; s/12XX/12th/; s/13XX/13th/' \
-e 's/1XX/1st/; s/2XX/2nd/; s/3XX/3rd/' \
-e 's/XX/th/; s/ / /'
}
ONE_DAY=$((60 * 60 * 24))
week_start=$(date -d "${*:-next Monday}" "+%s")
cat <<END
Week:: [[$(roam_date @$((${week_start} + ${ONE_DAY} * 0)))]]
## Top Weekly Goals
## [[Weekly Habits]]
-
## Daily Goals
- Monday: [[$( roam_date @$((${week_start} + ${ONE_DAY} * 0)))]]
- Tuesday: [[$( roam_date @$((${week_start} + ${ONE_DAY} * 1)))]]
- Wednesday: [[$(roam_date @$((${week_start} + ${ONE_DAY} * 2)))]]
- Thursday: [[$( roam_date @$((${week_start} + ${ONE_DAY} * 3)))]]
- Friday: [[$( roam_date @$((${week_start} + ${ONE_DAY} * 4)))]]
- Saturday: [[$( roam_date @$((${week_start} + ${ONE_DAY} * 5)))]]
- Sunday: [[$( roam_date @$((${week_start} + ${ONE_DAY} * 6)))]]
END
@pmbauer
Copy link
Author

pmbauer commented May 5, 2020

Examples

# print template for week starting next Monday
roam_wp

# print template for week starting 5/4/2020
roam_wp "05/04/2020"

# print template for last week
roam_wp last Monday
# print template for 4/27/2020 and copy to clipboard
$ roam_wp "04/27/2020" | tee >(pbcopy)
Week:: [[April 27th, 2020]]
## Top Weekly Goals
## [[Weekly Habits]]
  -
## Daily Goals
  - Monday: [[April 27th, 2020]]
  - Tuesday: [[April 28th, 2020]]
  - Wednesday: [[April 29th, 2020]]
  - Thursday: [[April 30th, 2020]]
  - Friday: [[May 1st, 2020]]
  - Saturday: [[May 2nd, 2020]]
  - Sunday: [[May 3rd, 2020]]

@kushagrasharma
Copy link

I'm getting this error when I run this: usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ...
[-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]

Any idea why this might be happening? Thanks for making this, by the way!

@pmbauer
Copy link
Author

pmbauer commented May 19, 2020

Script needs a GNU userland, so Linux or if you are on Mac I think brew install coreutils gnu-sed bash should get you the correct versions of date, sed and bash.

@matthewspear
Copy link

If running on macOS you'll need to change from date to gdate and that got it working for me!

Got super confused why you were passing a format to the daylight saving option '-d' then it clicked 😆 and I checked which date returns /bin/date belonging to the system and isn't the gnu one.

brew info coreutils also mentions this:

==> Caveats
Commands also provided by macOS have been installed with the prefix "g".
If you need to use these commands with their normal names, you
can add a "gnubin" directory to your PATH from your bashrc like:
  PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH"

@Singularity9
Copy link

I tried this on Manjaro linux and when I type "roam_wp" afterwards the terminal closes on me. Any idea why?

Thanks

@pmbauer
Copy link
Author

pmbauer commented Jun 6, 2020

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment