forked from zsh-users/zsh-completions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_baselayout
163 lines (150 loc) · 5.93 KB
/
_baselayout
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#compdef rc-update rc-status rc rc-service
# ------------------------------------------------------------------------------
# Copyright (c) 2011 Github zsh-users - http://github.com/zsh-users
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the zsh-users nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL ZSH-USERS BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ------------------------------------------------------------------------------
# Description
# -----------
#
# Completion script for Gentoo Baselayout v2 and OpenRC v0.8 (init system).
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
# * Vadim A. Misbakh-Soloviev <[email protected]>
# * Bapt <[email protected]>
# * kaworu <[email protected]>
# * David Durrleman <[email protected]>
# * oberyno <[email protected]>
# * Mamoru Komachi <[email protected]>
#
# ------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# ------------------------------------------------------------------------------
#<sys-apps/baselayout-1.12.11.1>
#
# Status:
# rc (fully done)
# rc-update (fully done)
# rc-status (fully done)
# rc-service (to be improved)
local gentoo_runlevels
gentoo_runlevels=(/etc/runlevels/*(:t))
# Stuff for rc
_rc () {
if (( CURRENT == 2 )); then
_values 'runlevels' $gentoo_runlevels
fi
}
_rc_list_service () {
local servicelist
servicelist=(${(f)"$(/sbin/rc-service -Cl 2>/dev/null)"})
_values 'services' $servicelist
}
# Stuff for rc-service
_rc-service () {
servicelist=${(f)"$(/sbin/rc-service -Cl 2>/dev/null)"}
if (( CURRENT == 2 ));then
_arguments -s \
'(-e --exists)'{-e,--exists}"[tests if the service exists or not]" \
'(-l --list)'{-l,--list}'[list all available services]' \
'(-r --resolve)'{-r,--resolve}'[resolve the service name to an init script]' \
'(-C --nocolor)'{-C,--nocolor}'[Disable color output]' \
'(-v --verbose)'{-v,--verbose}'[Run verbosely]' \
'(-q --quiet)'{-q,--quiet}'[Run quietly]'
_rc_list_service
else
case $words[2] in
-e|--exists|-r|--resolve)
(( CURRENT > 3 )) && return 0
_rc_list_service
;;
-*)
return 0
;;
*)
_values "action" stop start restart describe zap
;;
esac
fi
}
# Stuff for rc-status
_rc-status () {
_arguments -s \
'(-a --all)'{-a,--all}'[Show services at all run levels]' \
'(-l --list)'{-l,--list}'[Show list of run levels]' \
'(-nc --nocolor)'{-nc,--nocolor}'[Disable color output]' \
'(-s --servicelist)'{-s,--servicelist}'[Show all services]' \
'(-u --unused)'{-u,--unused}'[Show services not assigned to any run level]'
_values 'runlevels' $gentoo_runlevels
}
# Stuff for rc-update
_rc-update () {
local used_init
# FIXME: ${=${(f)"$(rc-update show 2>/dev/null)"}% |*} yield the same result (for me).
# we probably don't need any more the (M) matcher part.
used_init=(${=${(M)${(f)"$(/sbin/rc-update show 2>/dev/null)"}:#*|*[a-z]*}% |*})
if (( CURRENT == 2 )); then
_values 'rc-update actions' \
'add[Add script to a runlevel]' \
'del[Delete script from a runlevel]' \
'show[Show scripts lanched at a runlevel]' \
'-a[Add script to a runlevel]' \
'-d[Delete script from a runlevel]' \
'-s[Show scripts lanched at a runlevel]'
elif (( CURRENT == 3 )); then
case "$words[2]" in
add|-a)
_values 'scripts' /etc/init.d/*~*.sh(:t)
;;
del|-d)
_values 'scripts' $used_init
;;
show|-s)
_values 'runlevels' $gentoo_runlevels \
'-v[Show all init scripts]' \
'--verbose[Show all init scripts]'
;;
esac
elif (( CURRENT == 4 )); then
_values 'runlevels' $gentoo_runlevels
fi
}
case "$service" in
rc-update)
_rc-update "$@" && return 0
;;
rc-service)
_rc-service "$@" && return 0
;;
rc-status)
_rc-status "$@" && return 0
;;
rc)
_rc "$@" && return 0
;;
esac