about summary refs log tree commit diff
path: root/Completion/Unix/Command/_initctl
diff options
context:
space:
mode:
authorMikael Magnusson <mikachu@gmail.com>2011-05-27 00:12:51 +0000
committerMikael Magnusson <mikachu@gmail.com>2011-05-27 00:12:51 +0000
commitac8c1304ec853b3ce8fa3138e915b86857d92519 (patch)
tree891c3716dd256f118b089a8f41f26d0348fd335b /Completion/Unix/Command/_initctl
parenta75cbae6b7bfbaab78e32388e4a4118b3c818e8f (diff)
downloadzsh-ac8c1304ec853b3ce8fa3138e915b86857d92519.tar.gz
zsh-ac8c1304ec853b3ce8fa3138e915b86857d92519.tar.xz
zsh-ac8c1304ec853b3ce8fa3138e915b86857d92519.zip
29376: redefine _initctl too
Diffstat (limited to 'Completion/Unix/Command/_initctl')
-rw-r--r--Completion/Unix/Command/_initctl67
1 files changed, 35 insertions, 32 deletions
diff --git a/Completion/Unix/Command/_initctl b/Completion/Unix/Command/_initctl
index 08145b19e..11bd59b50 100644
--- a/Completion/Unix/Command/_initctl
+++ b/Completion/Unix/Command/_initctl
@@ -2,28 +2,7 @@
 # Written by Bernhard Tittelbach
 # based on completion script by Mildred
 
-local -a common_args
-common_args=(
-  '--session[use D-Bus session bus to connect to init daemon (for testing)]'
-  '--system[talk via DBUS system bus instead of socket]'
-  '(-q --quiet)'{-q,--quiet}'[reduce output to errors only]'
-  '(-v --verbose)'{-v,--verbose}'[increase output to include informational messages]'
-  '--dest=[D-Bus name for init, defaults to com.ubuntu.Upstart]'
-  '--help[display help and exit]'
-  '--version[output version information and exit]'
-)
-
-# don't overwrite work that we might have already done
-if (( ${+_initctl_events_list} + ${+_initctl_eventargs_list} != 2 )); then
-  typeset -g -a -U _initctl_events_list _initctl_eventargs_list
-fi
-
-# map each initctl function to a completion function
-local -A cmd_completion_funcs
-cmd_completion_funcs=( start startstop stop startstop restart startstop reload startstop show-config show-config status argjob emit emit check-config check-config )
-
-# define fallback completion function
-local cmd_completion_default=basic
+typeset -g -a -U _initctl_events_list _initctl_eventargs_list
 
 # run show-config -e and if possible parse out all events and KEY= argumnts
 # otherwise provide some common values
@@ -169,13 +148,37 @@ _initctl_check-config()
         '*::'
 }
 
-# depending on which command was used, call different completion funtions
-case $service in
-  initctl)
-    _arguments "${common_args[@]}" '*::Initctl Commands:_initctl_command'
-  ;;
-  start|stop|restart|reload|status)
-    _call_function ret _initctl_${cmd_completion_funcs[${service}]-${cmd_completion_default}}
-  ;;
-  *)  return 1  ;;
-esac
+# after defining above functions, overwrite _initctl function so helper-functions are loaded only once
+_initctl()
+{
+  local -a common_args
+  common_args=(
+    '--session[use D-Bus session bus to connect to init daemon (for testing)]'
+    '--system[talk via DBUS system bus instead of socket]'
+    '(-q --quiet)'{-q,--quiet}'[reduce output to errors only]'
+    '(-v --verbose)'{-v,--verbose}'[increase output to include informational messages]'
+    '--dest=[D-Bus name for init, defaults to com.ubuntu.Upstart]'
+    '--help[display help and exit]'
+    '--version[output version information and exit]'
+  )
+
+  # map each initctl function to a completion function
+  local -A cmd_completion_funcs
+  cmd_completion_funcs=( start startstop stop startstop restart startstop reload startstop show-config show-config status argjob emit emit check-config check-config )
+
+  # define fallback completion function
+  local cmd_completion_default=basic
+
+  # depending on which command was used, call different completion funtions
+  case $service in
+    initctl)
+      _arguments "${common_args[@]}" '*::Initctl Commands:_initctl_command'
+    ;;
+    start|stop|restart|reload|status)
+      _call_function ret _initctl_${cmd_completion_funcs[${service}]-${cmd_completion_default}}
+    ;;
+    *)  return 1  ;;
+  esac
+}
+
+_initctl "$@"