Last active
March 15, 2017 16:41
-
-
Save lufia/85cccd77dce1e60e1826cda455347384 to your computer and use it in GitHub Desktop.
doing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env rc | |
# usage: doing [-d yyyy-mm-dd] [message ...] | |
# ラベル | |
# 開始時間 | |
# 終了時間 | |
# (空行) | |
dir=$home/lib/doing | |
boundary=4 # 日付をまたぐ時間[0..$boundary][$boundary+1..23] | |
nights=`{seq -f %02g 0 $boundary} | |
if(~ `{date +%H} $nights) | |
key=`{date -v-$boundary^H +%Y-%m-%d} | |
if not | |
key=`{date +%Y-%m-%d} | |
file=$dir/$key | |
if(~ $1 -d){ | |
switch($2){ | |
case yesterday | |
s=`{9 ls -p $dir | sort | sed '/'$key'/,$d' | tail -1} | |
file=$dir/$s | |
case [0-9][0-9]-[0-9][0-9] | |
p=`{echo $2 | sed 's/././g'} | |
s=`{echo $key | sed 's/'$p'$//'} | |
file=$dir/$s$2 | |
case [0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] | |
file=$dir/$2 | |
case * | |
echo usage: `{basename $0} '[-d {[yyyy-]mm-dd|yesterday}] [message ...]' >[1=2] | |
exit usage | |
} | |
shift 2 | |
} | |
mkdir -p $dir | |
if(! test -f $file) | |
touch $file | |
switch($#*){ | |
case 0 | |
awk <$file ' | |
BEGIN { | |
FS = "\n" | |
RS = "" | |
unit = 15 # 単位時間 | |
} | |
NF == 3 { | |
print time($3 - $2), $1 | |
next | |
} | |
NF == 2 { | |
print "doing", $1 | |
next | |
} | |
{ printf "detects data is broken %s:%d\n", FILENAME, NR >"/dev/stderr" | |
} | |
function time(sec, min,n) { | |
min = int(sec / 60) | |
n = min % unit | |
return sprintf("%02d:%02d", int(min/60), min%60) | |
} | |
' | |
exit '' | |
} | |
now=`{date +%s} | |
s=`{tail -1 $file} | |
if(! ~ $#s 0){ | |
echo $now >>$file | |
echo >>$file | |
} | |
if(~ $"* .) | |
exit '' | |
echo $* >>$file | |
echo $now >>$file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment