Skip to content

Instantly share code, notes, and snippets.

@note103
Last active September 1, 2018 11:23
Show Gist options
  • Save note103/00f0559a74e1b3972768eff5052c5dd6 to your computer and use it in GitHub Desktop.
Save note103/00f0559a74e1b3972768eff5052c5dd6 to your computer and use it in GitHub Desktop.
For Scrapbox diary
# .bashrc
function sbdd {
local site="$1"
if [ -z "$site" ]; then return; fi
LANG=C
local ymd=$(date +%Y-%m-%d)
local y=$(echo $ymd | sed -e 's/\(.*\)-.*-.*/\1/')
local d=$(echo $ymd | sed -e 's/.*-\(.*-.*\)/\1/')
local w=$(date +%A)
local prev=$(date -v-1d +%Y-%m-%d)
local next=$(date -v+1d +%Y-%m-%d)
if [ ! -z "$2" ]; then
ymd="$2"
y=$(echo $ymd | sed -e 's/\(.*\)-.*-.*/\1/')
d=$(echo $ymd | sed -e 's/.*-\(.*-.*\)/\1/')
w=$(perl -MTime::Piece -E 'my $y = $ARGV[0]; my $ymd = localtime->strptime($y, "%Y-%m-%d"); print $ymd->fullday;' "$ymd")
date=$ymd
prev=$(perl -MTime::Piece -MTime::Seconds -E 'my $y = $ARGV[0]; my $ymd = localtime->strptime($y, "%Y-%m-%d"); my $prev = ($ymd - ONE_DAY)->ymd; print $prev;' "$ymd")
next=$(perl -MTime::Piece -MTime::Seconds -E 'my $y = $ARGV[0]; my $ymd = localtime->strptime($y, "%Y-%m-%d"); my $prev = ($ymd + ONE_DAY)->ymd; print $prev;' "$ymd")
fi
if [ ! -z $site ]; then
open "https://scrapbox.io/$site/$ymd?body=#$d #diary #$w #$y
prev: #$prev
next: #$next
"
fi
LANG=ja_JP.UTF-8
}
alias sddn="sbdd note103"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment