summaryrefslogtreecommitdiffstats
path: root/tv/5pkgs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2023-01-29 13:11:55 +0100
committertv <tv@krebsco.de>2023-01-29 13:11:55 +0100
commit895206d5c319418120f924db2fdaaaf188a66223 (patch)
tree611af1f81b6d92a3dbaeddbfa53ba0eaf230932a /tv/5pkgs
parent1766ee46bbf72b228894ce42c30e3bc655b7c449 (diff)
tv q: simplify calendar
Diffstat (limited to 'tv/5pkgs')
-rw-r--r--tv/5pkgs/simple/q/default.nix65
1 files changed, 20 insertions, 45 deletions
diff --git a/tv/5pkgs/simple/q/default.nix b/tv/5pkgs/simple/q/default.nix
index 2ae71db52..eb8462d57 100644
--- a/tv/5pkgs/simple/q/default.nix
+++ b/tv/5pkgs/simple/q/default.nix
@@ -10,53 +10,28 @@ let
hspace = 2;
# Return number of columns required to print n calenders side by side.
- need_width = n:
- assert n >= 1;
- n * calwidth + (n - 1) * hspace;
-
- pad = /* sh */ ''{
- ${pkgs.gnused}/bin/sed '
- # rtrim
- s/ *$//
-
- # delete last empty line
- ''${/^$/d}
- ' \
- | ${pkgs.gawk}/bin/awk '{printf "%-${toString calwidth}s\n", $0}' \
- | ${pkgs.gnused}/bin/sed '
- # colorize header
- 1,2s/.*/&/
-
- # colorize week number
- s/^[ 1-9][0-9]/&/
- '
- }'';
+ need_width = n: assert n >= 1; n * calwidth + (n - 1) * hspace;
+
in /* sh */ ''
cols=$(${pkgs.ncurses}/bin/tput cols)
- ${pkgs.coreutils}/bin/paste \
- <(if test $cols -ge ${toString (need_width 3)}; then
- ${pkgs.utillinux}/bin/cal -mw \
- $(${pkgs.coreutils}/bin/date +'%m %Y' -d 'last month') \
- | ${pad}
- fi) \
- <(if test $cols -ge ${toString (need_width 1)}; then
- ${pkgs.utillinux}/bin/cal -mw \
- | ${pkgs.gnused}/bin/sed '
- # colorize day of month
- s/\(^\| \)'"$(${pkgs.coreutils}/bin/date +%e)"'\>/&/
- ' \
- | ${pad}
- fi) \
- <(if test $cols -ge ${toString (need_width 2)}; then
- ${pkgs.utillinux}/bin/cal -mw \
- $(${pkgs.coreutils}/bin/date +'%m %Y' -d 'next month') \
- | ${pad}
- fi) \
- | ${pkgs.gnused}/bin/sed '
- s/^\t//
- s/\t$//
- s/\t/${lpad hspace " " ""}/g
- '
+ if test $cols -ge ${toString (need_width 3)}; then
+ ${pkgs.utillinux}/bin/cal --color=always -mw3
+ elif test $cols -ge ${toString (need_width 2)}; then
+ ${pkgs.utillinux}/bin/cal --color=always -mw -n 2
+ elif test $cols -ge ${toString (need_width 1)}; then
+ ${pkgs.utillinux}/bin/cal --color=always -mw1
+ else
+ :
+ fi |
+ ${pkgs.gnused}/bin/sed -r '
+ # dim week numbers
+ s/((^ *| )[ 1-5][0-9]( *)?)(([ 1-3][0-9])*)/\1\4/g
+ # dim month and day names
+ s/^ *[A-Z].*/&/
+ # highlight current date
+ s/\[7m//
+ s/\[27m//
+ '
'';
q-isodate = /* sh */ ''