summaryrefslogtreecommitdiffstats
path: root/tv/5pkgs/q
diff options
context:
space:
mode:
authornin <nineinchnade@gmail.com>2017-03-07 16:27:15 +0100
committernin <nineinchnade@gmail.com>2017-03-07 16:27:15 +0100
commit2edd8ca37b5c134b697315fd7ab603807760e6d6 (patch)
tree4fa4df81774907b797d04707028406788d7297e1 /tv/5pkgs/q
parent01868340e25ffb05ea8b784c5cdf47c251157dfb (diff)
parentc05db2409061f721ba454f4bf79e635ee13a6f11 (diff)
Merge remote-tracking branch 'prism/newest'
Diffstat (limited to 'tv/5pkgs/q')
-rw-r--r--tv/5pkgs/q/default.nix38
1 files changed, 29 insertions, 9 deletions
diff --git a/tv/5pkgs/q/default.nix b/tv/5pkgs/q/default.nix
index a3a7cd739..2e7aa5cf2 100644
--- a/tv/5pkgs/q/default.nix
+++ b/tv/5pkgs/q/default.nix
@@ -1,7 +1,19 @@
{ pkgs, ... }:
+with import <stockholm/lib>;
let
q-cal = let
- # XXX 23 is the longest line of cal's output
+
+ # Maximum width of cal's output.
+ calwidth = 23;
+
+ # Number of space characters between two calendars.
+ 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 = ''{
${pkgs.gnused}/bin/sed '
# rtrim
@@ -10,7 +22,7 @@ let
# delete last empty line
''${/^$/d}
' \
- | ${pkgs.gawk}/bin/awk '{printf "%-23s\n", $0}' \
+ | ${pkgs.gawk}/bin/awk '{printf "%-${toString calwidth}s\n", $0}' \
| ${pkgs.gnused}/bin/sed '
# colorize header
1,2s/.*/&/
@@ -20,23 +32,31 @@ let
'
}'';
in ''
+ cols=$(${pkgs.ncurses}/bin/tput cols)
${pkgs.coreutils}/bin/paste \
- <(${pkgs.utillinux}/bin/cal -mw \
+ <(if test $cols -ge ${toString (need_width 3)}; then
+ ${pkgs.utillinux}/bin/cal -mw \
$(${pkgs.coreutils}/bin/date +'%m %Y' -d 'last month') \
| ${pad}
- ) \
- <(${pkgs.utillinux}/bin/cal -mw \
+ 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}
- ) \
- <(${pkgs.utillinux}/bin/cal -mw \
+ 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}
- ) \
- | ${pkgs.gnused}/bin/sed 's/\t/ /g'
+ fi) \
+ | ${pkgs.gnused}/bin/sed '
+ s/^\t//
+ s/\t$//
+ s/\t/${lpad hspace " " ""}/g
+ '
'';
q-isodate = ''