From 37a4dce4bc5b38a686516e22d0dc81a90b757d91 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 10 Dec 2008 13:30:27 +0000 Subject: 26121: add -B option to calendar --- Functions/Calendar/calendar | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'Functions/Calendar/calendar') diff --git a/Functions/Calendar/calendar b/Functions/Calendar/calendar index 246cf2383..1338aa9f8 100644 --- a/Functions/Calendar/calendar +++ b/Functions/Calendar/calendar @@ -60,7 +60,7 @@ while [[ ${argv[opti+1]} = -* ]]; do ######################## # Options with arguments ######################## - ([CnS]) + ([BCnS]) if [[ -n $optrest ]]; then optarg=$optrest optrest= @@ -72,6 +72,15 @@ while [[ ${argv[opti+1]} = -* ]]; do return 1 fi case $opt in + (B) + # Brief, with number of lines to show. + brief=$optarg + if (( brief <= 0 )); then + print -r "$0: option -$opt requires a positive integer." >&2 + return 1 + fi + ;; + (C) # Pick the calendar file, overriding style and default. calendar=$optarg @@ -289,17 +298,17 @@ fi fi (( shown = 0 )) if (( brief )); then - showline=${line%%$'\n'*} + showline=${(F)${${(f)line}[1,brief]}} else showline=$line - match=() - # Strip continuation lines starting " #". - while [[ $showline = (#b)(*$'\n')[[:space:]]##\#[^$'\n']##(|$'\n'(*)) ]]; do - showline="$match[1]$match[3]" - done - # Strip trailing empty lines - showline=${showline%%[[:space:]]#} fi + match=() + # Strip continuation lines starting " #". + while [[ $showline = (#b)(*$'\n')[[:space:]]##\#[^$'\n']##(|$'\n'(*)) ]]; do + showline="$match[1]$match[3]" + done + # Strip trailing empty lines + showline=${showline%%[[:space:]]#} if (( showall || (t >= start && (remaining || t <= stop || icount < showcount)) )) then $showprog $start $stop "$showline" -- cgit 1.4.1