diff options
author | tv <tv@krebsco.de> | 2019-01-16 20:25:17 +0100 |
---|---|---|
committer | tv <tv@krebsco.de> | 2019-01-16 20:39:22 +0100 |
commit | 0ef96fc0cf8bf85be36f2911923a91143a484fdc (patch) | |
tree | 4f8cc216219f900d62b980ad6040d4291a276fea /tv/5pkgs | |
parent | 6c734674da365c2529505a78dea9317f74dec260 (diff) |
tv q-todo: awk,bash,cat,date -> jq
Diffstat (limited to 'tv/5pkgs')
-rw-r--r-- | tv/5pkgs/simple/q/default.nix | 33 |
1 files changed, 13 insertions, 20 deletions
diff --git a/tv/5pkgs/simple/q/default.nix b/tv/5pkgs/simple/q/default.nix index 6c1876ab0..0e2aecb27 100644 --- a/tv/5pkgs/simple/q/default.nix +++ b/tv/5pkgs/simple/q/default.nix @@ -269,26 +269,19 @@ let q-todo = /* sh */ '' TODO_file=$PWD/TODO if test -e "$TODO_file"; then - ${pkgs.coreutils}/bin/cat "$TODO_file" \ - | ${pkgs.gawk}/bin/gawk -v now=$(${pkgs.coreutils}/bin/date +%s) ' - BEGIN { print "remind=0" } - /^[0-9]/{ - x = $1 - gsub(".", "\\\\&", x) - rest = substr($0, index($0, " ")) - rest = $0 - sub(" *", "", rest) - gsub(".", "\\\\&", rest) - print "test $(${pkgs.coreutils}/bin/date +%s -d"x") -lt "now" && \ - echo \"\x1b[38;5;208m\""rest esc "\"\x1b[m\" && \ - (( remind++ ))" - } - END { print "test $remind = 0 && echo \"nothing to remind\"" } - ' \ - | { - # bash needed for (( ... )) - ${pkgs.bash}/bin/bash - } + ${pkgs.jq}/bin/jq -Rrs <"$TODO_file" -f ${pkgs.writeJq "q-todo.jq" '' + split("\n") | map( + (match("^([0-9]+-\\d{2}-\\d{2})\\s+(.*)$").captures | map(.string)) + as $captures | + ($captures[0] | strptime("%Y-%m-%d") | mktime) as $date | + $captures[1] as $text | + + select(now >= $date) | + + "\u001b[38;5;208m\(.)\u001b[m" + ) | + if length == 0 then "nothing to remind" else .[] end + ''} else echo "$TODO_file: no such file or directory" fi |