summaryrefslogtreecommitdiff
path: root/completions/service
diff options
context:
space:
mode:
Diffstat (limited to 'completions/service')
-rw-r--r--completions/service47
1 files changed, 47 insertions, 0 deletions
diff --git a/completions/service b/completions/service
new file mode 100644
index 00000000..1a36f59b
--- /dev/null
+++ b/completions/service
@@ -0,0 +1,47 @@
+# service(8) and /etc/init.d/* completion
+
+# This completes on a list of all available service scripts for the
+# 'service' command and/or the SysV init.d directory, followed by
+# that script's available commands
+#
+{ have service || [ -d /etc/init.d/ ]; } &&
+_service()
+{
+ local cur prev sysvdir
+
+ COMPREPLY=()
+ _get_comp_words_by_ref cur prev
+
+ # don't complete for things like killall, ssh and mysql if it's
+ # the standalone command, rather than the init script
+ [[ ${COMP_WORDS[0]} != @(*init.d/!(functions|~)|service) ]] && return 0
+
+ # don't complete past 2nd token
+ [ $COMP_CWORD -gt 2 ] && return 0
+
+ if [[ $COMP_CWORD -eq 1 && $prev == "service" ]]; then
+ _services
+ else
+ [ -d /etc/rc.d/init.d ] && \
+ sysvdir=/etc/rc.d/init.d || sysvdir=/etc/init.d
+ COMPREPLY=( $( compgen -W '`sed -e "y/|/ /" \
+ -ne "s/^.*\(U\|msg_u\)sage.*{\(.*\)}.*$/\2/p" \
+ $sysvdir/${prev##*/} 2>/dev/null`' -- "$cur" ) )
+ fi
+
+ return 0
+} &&
+complete -F _service service
+for svc in /etc/init.d/*; do
+ [ ! -x "$svc" ] || complete -p "${svc##*/}" &>/dev/null || \
+ complete -F _service -o default "${svc##*/}"
+done
+unset svc
+
+# Local variables:
+# mode: shell-script
+# sh-basic-offset: 4
+# sh-indent-comment: t
+# indent-tabs-mode: nil
+# End:
+# ex: ts=4 sw=4 et filetype=sh