Instantly share code, notes, and snippets.

@note103 /.bashrc.bash Secret
Last active Sep 1, 2018

Embed
What would you like to do?
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