[systemd-devel] [PATCH 3/3] completion: add ZSH support
Ramkumar Ramachandra
artagnon at gmail.com
Fri Dec 2 08:44:33 PST 2011
Adding support for ZSH requires two changes:
1. The syntax for initializing associative arrays are different in
Bash 4 and ZSH. However, array access has the same syntax in both- so
use explicit assignments.
2. Bash uses a different completion system, and the function
complete() is undefined in ZSH. However, the bashcompinit feature in
ZSH implements this complete(): use it.
Signed-off-by: Ramkumar Ramachandra <artagnon at gmail.com>
---
src/systemd-bash-completion.sh | 50 ++++++++++++++++++++-------------------
1 files changed, 26 insertions(+), 24 deletions(-)
diff --git a/src/systemd-bash-completion.sh b/src/systemd-bash-completion.sh
index 9f58b06..41de526 100644
--- a/src/systemd-bash-completion.sh
+++ b/src/systemd-bash-completion.sh
@@ -15,6 +15,10 @@
# You should have received a copy of the GNU General Public License
# along with systemd; If not, see <http://www.gnu.org/licenses/>.
+if [[ -n ${ZSH_VERSION-} ]]; then
+ autoload -U +X bashcompinit && bashcompinit
+fi
+
__systemctl() {
systemctl --full --no-legend "$@"
}
@@ -48,12 +52,11 @@ _systemctl () {
local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
local verb comps
- local -A OPTS=(
- [STANDALONE]='--all -a --defaults --fail --ignore-dependencies --failed --force -f --full --global
+ local -A OPTS
+ OPTS[STANDALONE]='--all -a --defaults --fail --ignore-dependencies --failed --force -f --full --global
--help -h --no-ask-password --no-block --no-legend --no-pager --no-reload --no-wall
--order --require --quiet -q --privileged -P --system --user --version --runtime'
- [ARG]='--host -H --kill-mode --kill-who --property -p --signal -s --type -t --root'
- )
+ OPTS[ARG]='--host -H --kill-mode --kill-who --property -p --signal -s --type -t --root'
if __contains_word "$prev" ${OPTS[ARG]}; then
case $prev in
@@ -90,26 +93,25 @@ _systemctl () {
return 0
fi
- local -A VERBS=(
- [ALL_UNITS]='is-active is-enabled status show mask preset'
- [ENABLED_UNITS]='disable reenable'
- [DISABLED_UNITS]='enable'
- [FAILED_UNITS]='reset-failed'
- [STARTABLE_UNITS]='start'
- [STOPPABLE_UNITS]='stop condstop kill try-restart condrestart'
- [ISOLATABLE_UNITS]='isolate'
- [RELOADABLE_UNITS]='reload condreload reload-or-try-restart force-reload'
- [RESTARTABLE_UNITS]='restart reload-or-restart'
- [MASKED_UNITS]='unmask'
- [JOBS]='cancel'
- [SNAPSHOTS]='delete'
- [ENVS]='set-environment unset-environment'
- [STANDALONE]='daemon-reexec daemon-reload default dot dump
- emergency exit halt kexec list-jobs list-units
- list-unit-files poweroff reboot rescue show-environment'
- [NAME]='snapshot load'
- [FILE]='link'
- )
+ local -A VERBS
+ VERBS[ALL_UNITS]='is-active is-enabled status show mask preset'
+ VERBS[ENABLED_UNITS]='disable reenable'
+ VERBS[DISABLED_UNITS]='enable'
+ VERBS[FAILED_UNITS]='reset-failed'
+ VERBS[STARTABLE_UNITS]='start'
+ VERBS[STOPPABLE_UNITS]='stop condstop kill try-restart condrestart'
+ VERBS[ISOLATABLE_UNITS]='isolate'
+ VERBS[RELOADABLE_UNITS]='reload condreload reload-or-try-restart force-reload'
+ VERBS[RESTARTABLE_UNITS]='restart reload-or-restart'
+ VERBS[MASKED_UNITS]='unmask'
+ VERBS[JOBS]='cancel'
+ VERBS[SNAPSHOTS]='delete'
+ VERBS[ENVS]='set-environment unset-environment'
+ VERBS[STANDALONE]='daemon-reexec daemon-reload default dot dump
+ emergency exit halt kexec list-jobs list-units
+ list-unit-files poweroff reboot rescue show-environment'
+ VERBS[NAME]='snapshot load'
+ VERBS[FILE]='link'
for ((i=0; $i <= $COMP_CWORD; i++)); do
if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
--
1.7.6.351.gb35ac.dirty
More information about the systemd-devel
mailing list