aboutsummaryrefslogtreecommitdiff
path: root/bash-completion/openrc-service-script
diff options
context:
space:
mode:
authorWilliam Hubbs <w.d.hubbs@gmail.com>2017-12-06 13:21:25 -0600
committerWilliam Hubbs <w.d.hubbs@gmail.com>2017-12-06 13:25:26 -0600
commitd220fc272337b216bff6ac781a7b6be4e6f3caee (patch)
treecd1411ccf2569faa87d64d8cdedfde2130aa0f9a /bash-completion/openrc-service-script
parenta2447dfb420cbd97a65cc085404c031d42cb3dfb (diff)
add bash completion support
This fixes #188.
Diffstat (limited to 'bash-completion/openrc-service-script')
-rw-r--r--bash-completion/openrc-service-script29
1 files changed, 29 insertions, 0 deletions
diff --git a/bash-completion/openrc-service-script b/bash-completion/openrc-service-script
new file mode 100644
index 00000000..455ad05f
--- /dev/null
+++ b/bash-completion/openrc-service-script
@@ -0,0 +1,29 @@
+# Copyright (c) 2017 The OpenRC Authors.
+# See the Authors file at the top-level directory of this distribution and
+# https://github.com/OpenRC/openrc/blob/master/AUTHORS
+#
+# This file is part of OpenRC. It is subject to the license terms in
+# the LICENSE file found in the top-level directory of this
+# distribution and at https://github.com/OpenRC/openrc/blob/master/LICENSE
+# This file may not be copied, modified, propagated, or distributed
+# except according to the terms contained in the LICENSE file.
+
+_openrc_service_script()
+{
+ local script="${COMP_WORDS[0]}"
+ local cur="${COMP_WORDS[$COMP_CWORD]}"
+
+ if [[ ( -f "${script}" || -h "${script}" ) && -r "${script}" ]] \
+ && [[ "$(head -n 1 "${script}")" =~ \#\!.*/openrc-run ]]
+ then
+ [[ $COMP_CWORD -gt 1 ]] && return 1
+ COMPREPLY=($(opts="start stop status restart pause zap ineed needsme iuse usesme broken"; \
+ eval "$(grep '^opts=' "${script}")"; echo "${opts}"))
+ [[ -n "$COMPREPLY" ]] || COMPREPLY=(start stop restart zap)
+ COMPREPLY=($(compgen -W "${COMPREPLY[*]}" -- "${cur}"))
+ else
+ COMPREPLY=($(compgen -o default -- "${cur}"))
+ fi
+ return 0
+}
+complete -F _openrc_service_script */etc/init.d/*