Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

PATCH: _calendar



This adds completion for the calendar function and also makes it
possible to trace what precommand modifiers are in effect, so for
example we can tell if we're executing an external command with the same
name as a function.

Index: Completion/Base/Core/_main_complete
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Base/Core/_main_complete,v
retrieving revision 1.10
diff -u -r1.10 _main_complete
--- Completion/Base/Core/_main_complete	1 Oct 2004 10:29:21 -0000	1.10
+++ Completion/Base/Core/_main_complete	1 Apr 2009 10:45:40 -0000
@@ -32,6 +32,9 @@
       _saved_insert="${compstate[insert]}" \
       _saved_colors="$ZLS_COLORS"
 
+# _precommand sets this to indicate we are following a precommand modifier
+local -a precommands
+
 typeset -U _lastdescr _comp_ignore _comp_colors
 
 [[ -z "$curcontext" ]] && curcontext=:::
Index: Completion/Unix/Command/_calendar
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Unix/Command/_calendar,v
retrieving revision 1.1
diff -u -r1.1 _calendar
--- Completion/Unix/Command/_calendar	12 Mar 2008 23:35:26 -0000	1.1
+++ Completion/Unix/Command/_calendar	1 Apr 2009 10:45:41 -0000
@@ -1,12 +1,34 @@
 #compdef calendar
 
-_arguments \
-  '-a[process files of all users]' \
-  '-A[print today and the following num days]:number of days:' \
-  '-b[enforce special KOI8 date calculation mode]' \
-  '-B[print today and the previous num days]:number of days:' \
-  '-f[use file as the default calendar]:calendar file:_files' \
-  '-l[print today and the following num days]:number of days:' \
-  '-w[print today and the following num days only if today is Friday]:number of days:' \
-  '-t[act as though today is the date specified]:date:'
+if [[ $+functions[calendar] -eq 1 && -z $precommands[(r)command] ]]; then
+  # The shell function is loaded, and we're not instructed to
+  # use an external command, so complete that.
+  _arguments \
+    '-a[show all calendar items]' \
+    '-b[brief, display first line only]' \
+    '-d[move events to done file]' \
+    '-D[never move events to done file]' \
+    '-r[show all remaining items from start or now]' \
+    '-s[use sched to schedule a warning]' \
+    '-v[verbose]' \
+    '-B[select number of lines to display]:lines: ' \
+    '-C[select calendar file]:calendar file:_path_files' \
+    '-n[select max number of events]:max number of events: ' \
+    '-S[select show programme]:show programme:_command_names' \
+    '1:date/time: ' \
+    '(-r)2:end date/time: '
+else
+  # This is only one particular version of calendar.
+  # Some variant of BSD, I think.
 
+  _arguments \
+    '-a[process files of all users]' \
+    '-A[print today and the following num days]:number of days:' \
+    '-b[enforce special KOI8 date calculation mode]' \
+    '-B[print today and the previous num days]:number of days:' \
+    '-f[use file as the default calendar]:calendar file:_files' \
+    '-l[print today and the following num days]:number of days:' \
+    '-w[print today and the following num days only if today is Friday]:number of days:' \
+    '-t[act as though today is the date specified]:date:'
+
+fi
Index: Completion/Zsh/Command/_command
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Command/_command,v
retrieving revision 1.2
diff -u -r1.2 _command
--- Completion/Zsh/Command/_command	19 Aug 2007 23:31:31 -0000	1.2
+++ Completion/Zsh/Command/_command	1 Apr 2009 10:45:41 -0000
@@ -2,6 +2,8 @@
 
 local ret
 
+# indicate if this is a precommand modifier
+[[ $service = command ]] && precommands+=(command)
 if [[ CURRENT -ge 3 ]]; then
   compset -n 2
   _normal && ret=0
Index: Completion/Zsh/Command/_precommand
===================================================================
RCS file: /cvsroot/zsh/zsh/Completion/Zsh/Command/_precommand,v
retrieving revision 1.6
diff -u -r1.6 _precommand
--- Completion/Zsh/Command/_precommand	30 Aug 2008 11:49:20 -0000	1.6
+++ Completion/Zsh/Command/_precommand	1 Apr 2009 10:45:41 -0000
@@ -1,5 +1,8 @@
 #compdef - nohup eval time rusage noglob nocorrect exec catchsegv aoss
 
+# precommands is made local in _main_complete
+precommands+=($words[1])
+
 shift words
 (( CURRENT-- ))
 

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070



Messages sorted by: Reverse Date, Date, Thread, Author