about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2008-12-10 13:30:27 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2008-12-10 13:30:27 +0000
commit37a4dce4bc5b38a686516e22d0dc81a90b757d91 (patch)
treefe372a4b26198b41ccad2f0ac28613abd39c55df
parent63e60d3d21ebfd985d83a5359b8e5bc68de5dcaf (diff)
downloadzsh-37a4dce4bc5b38a686516e22d0dc81a90b757d91.tar.gz
zsh-37a4dce4bc5b38a686516e22d0dc81a90b757d91.tar.xz
zsh-37a4dce4bc5b38a686516e22d0dc81a90b757d91.zip
26121: add -B <lines> option to calendar
-rw-r--r--ChangeLog3
-rw-r--r--Doc/Zsh/calsys.yo4
-rw-r--r--Functions/Calendar/calendar27
3 files changed, 25 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 245791863..c91ceb9bf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,8 @@
 2008-12-10  Peter Stephenson  <pws@csr.com>
 
+	* 26121: Doc/Zsh/calsys.yo, Functions/Calendar/calendar: add
+	-B <lines> option to calendar.
+
 	* users/13566: Etc/FAQ.yo: note problem with unsetting elements
 	of regular arrays.
 
diff --git a/Doc/Zsh/calsys.yo b/Doc/Zsh/calsys.yo
index 934746f08..05a644f2e 100644
--- a/Doc/Zsh/calsys.yo
+++ b/Doc/Zsh/calsys.yo
@@ -357,6 +357,10 @@ item(tt(-b))(
 Brief:  don't display continuation lines (i.e. indented lines following
 the line with the date/time), just the first line.
 )
+item(tt(-B) var(lines))(
+Brief: display at most the first var(lines) lines of the calendar
+entry.  `tt(-B 1)' is equivalent to `tt(-b)'.
+)
 item(tt(-C) var(calfile))(
 Explicitly specify a calendar file instead of the value of
 the tt(calendar-file) style or the the default tt(~/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"