about summary refs log tree commit diff
diff options
context:
space:
mode:
authordana <dana@dana.is>2018-07-19 21:17:30 -0500
committerdana <dana@dana.is>2018-07-19 21:17:30 -0500
commit3ec9503f496a25cef96bd3ca42bf88d5a71322de (patch)
tree53e2160669e98cc26c8a33f330dc51af7df96de1
parent218a7e324dc52e5b9f2e724c1463fb0643a6036f (diff)
downloadzsh-3ec9503f496a25cef96bd3ca42bf88d5a71322de.tar.gz
zsh-3ec9503f496a25cef96bd3ca42bf88d5a71322de.tar.xz
zsh-3ec9503f496a25cef96bd3ca42bf88d5a71322de.zip
43186: Add completion for cronie/dcron/Vixie crontab
Minor change from the patch as posted to the ML: BusyBox variant detection has
been expanded to cover dcron (which BusyBox's crontab is forked from).
-rw-r--r--ChangeLog5
-rw-r--r--Completion/Unix/Command/_crontab68
2 files changed, 73 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 8a37503ba..21a910ae3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2018-07-19  dana  <dana@dana.is>
+
+	* 43186 (tweaked): Completion/Unix/Command/_crontab: Add completion
+	for cronie/dcron/Vixie crontab
+
 2018-07-19  Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>
 
 	* 43189: Completion/Unix/Command/_install: similar fix as 43187
diff --git a/Completion/Unix/Command/_crontab b/Completion/Unix/Command/_crontab
new file mode 100644
index 000000000..cda7549a1
--- /dev/null
+++ b/Completion/Unix/Command/_crontab
@@ -0,0 +1,68 @@
+#compdef crontab
+
+# Notes:
+# - We assume a cronie-, dcron-, or Vixie-esque crontab
+# - BusyBox crontab is forked from dcron
+# - Generally only the super-user can use -c/-u; we aren't that restrictive
+# - @todo As usual, BusyBox multi-call isn't handled
+
+local variant sluser
+local -a args etargs ccargs clargs rcargs aopts
+
+_pick_variant -r variant \
+  dcron='-c*(#i)dir' \
+  cronie-selinux='(#i)selinux' \
+  cronie='(#i)cluster' \
+  unix --help
+variant+=-$OSTYPE
+
+# On Solaris, instead of using -u, the user can be specified as an optional
+# first operand with -e/-l/-r. We'll treat it as an optional *argument* to one
+# of those options, though, since the logic is a bit simpler
+if [[ $variant == *-solaris* ]]; then
+  sluser='::user whose crontab to work with:_users'
+else
+  etargs+=( '(cl)-u+[specify user whose crontab to work with]: :_users' )
+fi
+
+case $variant in
+  dcron-*)
+    etargs+=( '-c+[specify crontab directory]:crontab directory:_directories' )
+    ;;
+  cronie-selinux-*)
+    ccargs+=( '(-l cl nc rc)-s[append SELinux context (with -e)]' )
+    ;& # FALL THROUGH
+  cronie-*)
+    etargs+=( '(: * -)-V[display version information]' )
+    clargs+=(
+      '(: * -)-c[display cluster host]'
+      '(: * -)-n+[specify cluster host]: :_hosts'
+    )
+    ;& # FALL THROUGH
+  *-linux*)
+    rcargs+=( '(cc cl nc)-i[prompt for confirmation (with -r)]' )
+    ;;
+  *-freebsd*)
+    rcargs+=( '(cc cl nc)-f[bypass confirmation prompt (with -r)]' )
+    ;;
+esac
+
+(( $#etargs )) && args+=( + et $etargs ) # Misc.
+(( $#clargs )) && args+=( + cl $clargs ) # Work with cluster
+args+=(
+  + nc # Install new crontab
+  '(cc cl rc sl):crontab to install:_files'
+  + cc # Edit/display current crontab
+  "(-l cl nc rc)-e[edit current crontab]$sluser"
+  "(-e -s cl nc rc)-l[display current crontab]$sluser"
+  $ccargs
+  + rc # Remove current crontab
+  "(cc cl nc)-r[remove current crontab]$sluser"
+  $rcargs
+)
+
+# Implementations that use GNU's getopt(3) probably support permutation; this
+# should be accurate enough
+[[ $OSTYPE == linux* ]] || aopts=( -A '-*' )
+
+_arguments -s -S $aopts : $args