From 04774c1a12bf923ca39a69607c35df2c5350b985 Mon Sep 17 00:00:00 2001 From: Florian Fischer Date: Wed, 17 Feb 2016 15:28:25 +0100 Subject: add function to plot a month + __mark_print_block: + function to print a specified block from the store file to stdout + arguments: block name, store location + __mark_print_month: + this functions use the output from cal and colors marked days + possible arguments: "-s=" store location, "-y= | -m=" year and month to print + if nothing is specified the current month is plotted --- functions/__mark_print_block.fish | 5 +++ functions/__mark_print_month.fish | 77 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 functions/__mark_print_block.fish create mode 100644 functions/__mark_print_month.fish (limited to 'functions') diff --git a/functions/__mark_print_block.fish b/functions/__mark_print_block.fish new file mode 100644 index 0000000..761bcb5 --- /dev/null +++ b/functions/__mark_print_block.fish @@ -0,0 +1,5 @@ +function __mark_print_block -d "prints block from mark_store" -a block file + set c (string match -r "#$block#[^#]*" (echo (cat $file))) + set c (string replace "#$block#" "" $c) + echo (string trim $c) +end diff --git a/functions/__mark_print_month.fish b/functions/__mark_print_month.fish new file mode 100644 index 0000000..80ae94e --- /dev/null +++ b/functions/__mark_print_month.fish @@ -0,0 +1,77 @@ +function __mark_print_month --description "print overview over a month" + + # defaults + # use current year and month + set mark_store $__mark_store + # convert "0m" to "m" if m < 10 + set month (math (date "+%m") "*1") + set year (date "+%Y") + + # parse argv + for i in (seq 1 (count $argv)) + if string match -q -- "-y=*" "$argv[$i]" + set year (string replace -- "-y=" "" $argv[$i]) + else if string match -q -- "-m=*" "$argv[$i]" + set month (string replace -- "-m=" "" $argv[$i]) + else if string match -q -- "-s=*" "$argv[$i]" + set mark_store (string replace -- "-s=" "" "$argv[$i]") + else + echo unrecognised option: $argv[$i] >&2 + return 1 + end + end + + if not test -f $mark_store + return 1 + end + + # get marks + set marks (string split " " (__mark_print_block "store" $mark_store)) + set marks (string split ":" $marks[(math $month + 1)])[2] + set marks (string split "" $marks) + + # get colors + set colors (__mark_print_block "colors" $mark_store) + + # get formatted representation for month + set month (cal $month $year) + # strip of headline + set month $month[2..-1] + # day count + set day 1 + for l in $month + set chars (string split "" $l) + set cursor 1 + # used if day is double-digit + set cursor_n $cursor + while test $cursor -le (count $chars) + if string match -q -r "[0-9]" $chars[$cursor] + if test (string length $day) -eq 2 + set cursor_n (math $cursor + 1) + end + if test $marks[$day] != "?" + # find color + if set col (string match -r "$marks[$day]:[^\ ]*" $colors) + set col (string split ":" $col)[2] + set_color $col + else + # default to yellow + set_color yellow + end + + echo -n (string join "" $chars[$cursor..$cursor_n]) + set_color normal + else + echo -n (string join "" $chars[$cursor..$cursor_n]) + end + test $cursor_n -ne $cursor; and set cursor (math $cursor + 1) + set day (math $day + 1) + else + echo -n $chars[$cursor] + end + set cursor (math $cursor + 1) + set cursor_n $cursor + end + echo + end +end -- cgit v1.2.3