]>
Commit | Line | Data |
---|---|---|
36f186a9 | 1 | # homectl(1) completion -*- shell-script -*- |
db9ecf05 | 2 | # SPDX-License-Identifier: LGPL-2.1-or-later |
3a9692dd ZJS |
3 | # |
4 | # This file is part of systemd. | |
5 | # | |
6 | # systemd is free software; you can redistribute it and/or modify it | |
7 | # under the terms of the GNU Lesser General Public License as published by | |
8 | # the Free Software Foundation; either version 2.1 of the License, or | |
9 | # (at your option) any later version. | |
10 | # | |
11 | # systemd is distributed in the hope that it will be useful, but | |
12 | # WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | # General Public License for more details. | |
15 | # | |
16 | # You should have received a copy of the GNU Lesser General Public License | |
85fce6f4 | 17 | # along with systemd; If not, see <https://www.gnu.org/licenses/>. |
3a9692dd ZJS |
18 | |
19 | __contains_word () { | |
20 | local w word=$1; shift | |
21 | for w in "$@"; do | |
22 | [[ $w = "$word" ]] && return | |
23 | done | |
24 | } | |
25 | ||
26 | __get_machines() { | |
27 | local a b | |
28 | machinectl list --full --no-legend --no-pager 2>/dev/null | | |
29 | { while read a b; do echo " $a"; done; }; | |
30 | } | |
31 | ||
32 | __get_homes() { | |
33 | homectl --no-pager --no-legend list 2>/dev/null | |
34 | } | |
35 | ||
36 | _homectl() { | |
37 | local i verb comps | |
38 | local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} | |
39 | ||
40 | local -A OPTS=( | |
41 | [STANDALONE]='-h --help --version | |
42 | --no-pager --no-legend --no-ask-password | |
43 | -j -E -P' | |
44 | [ARG]=' -H --host | |
45 | -M --machine | |
46 | --identity | |
47 | --json | |
48 | --export-format | |
49 | -c --real-name | |
50 | --realm | |
51 | --email-address | |
52 | --location | |
53 | --icon-name | |
54 | -d --home-dir | |
55 | --uid | |
56 | -G --member-of | |
57 | --skel | |
58 | --shell | |
59 | --setenv | |
60 | --timezone | |
61 | --language | |
62 | --ssh-authorized-keys | |
63 | --pkcs11-token-uri | |
64 | --locked | |
65 | --not-before | |
66 | --not-after | |
67 | --rate-limit-interval | |
68 | --rate-limit-burst | |
69 | --password-hint | |
70 | --enforce-password-policy | |
71 | --password-change-now | |
72 | --password-change-min | |
73 | --password-change-max | |
74 | --password-change-warn | |
75 | --password-change-inactive | |
76 | --disk-size | |
77 | --access-mode | |
78 | --umask | |
79 | --nice | |
80 | --rlimit | |
81 | --tasks-max | |
82 | --memory-high | |
83 | --memory-max | |
84 | --cpu-weight | |
85 | --io-weight | |
86 | --storage | |
87 | --image-path | |
88 | --fs-type | |
89 | --luks-discard | |
90 | --luks-offline-discard | |
91 | --luks-cipher | |
92 | --luks-cipher-mode | |
93 | --luks-volume-key-size | |
94 | --luks-pbkdf-type | |
95 | --luks-pbkdf-hash-algorithm | |
b04ff66b | 96 | --luks-pbkdf-force-iterations |
3a9692dd ZJS |
97 | --luks-pbkdf-time-cost |
98 | --luks-pbkdf-memory-cost | |
99 | --luks-pbkdf-parallel-threads | |
fd83c98e | 100 | --luks-sector-size |
3a9692dd ZJS |
101 | --nosuid |
102 | --nodev | |
103 | --noexec | |
104 | --cifs-domain | |
105 | --cifs-user-name | |
106 | --cifs-service | |
107 | --stop-delay | |
108 | --kill-processes | |
25c89b89 AV |
109 | --auto-login |
110 | -b --blob | |
111 | --avatar | |
112 | --login-background' | |
3a9692dd ZJS |
113 | ) |
114 | ||
115 | if __contains_word "$prev" ${OPTS[ARG]}; then | |
116 | case $prev in | |
117 | --host|-H) | |
118 | comps=$(compgen -A hostname) | |
119 | ;; | |
120 | --machine|-M) | |
121 | comps=$( __get_machines ) | |
122 | ;; | |
25c89b89 | 123 | --identity|--image-path|--avatar|--login-background) |
3a9692dd ZJS |
124 | comps=$(compgen -A file -- "$cur" ) |
125 | compopt -o filenames | |
126 | ;; | |
127 | --json) | |
128 | comps='pretty short off' | |
129 | ;; | |
130 | --export-format) | |
131 | comps='full stripped minimal' | |
132 | ;; | |
133 | --locked|--enforce-password-policy|--password-change-now|--luks-discard|--luks-offline-discard|--nosuid|--nodev|--noexec|--kill-processes|--auto-login) | |
134 | comps='yes no' | |
135 | ;; | |
25c89b89 | 136 | -d|--home-dir|--skel|-b|--blob) |
3a9692dd ZJS |
137 | comps=$(compgen -A directory -- "$cur" ) |
138 | compopt -o dirnames | |
139 | ;; | |
140 | -G|--member-of) | |
141 | comps=$(compgen -A group -- "$cur" ) | |
142 | ;; | |
143 | --shell) | |
144 | comps=$(cat /etc/shells) | |
145 | ;; | |
146 | --fs-type) | |
caf6bd16 | 147 | comps='btrfs ext4 xfs' |
3a9692dd ZJS |
148 | ;; |
149 | --cifs-user-name) | |
150 | comps=$(compgen -A user -- "$cur" ) | |
151 | ;; | |
49e55abb AV |
152 | --language) |
153 | comps=$(localectl list-locales 2>/dev/null) | |
154 | ;; | |
3a9692dd ZJS |
155 | esac |
156 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
157 | return 0 | |
158 | fi | |
159 | ||
160 | if [[ "$cur" = -* ]]; then | |
161 | COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) | |
162 | return 0 | |
163 | fi | |
164 | ||
165 | local -A VERBS=( | |
166 | [STANDALONE]='list lock-all' | |
167 | [CREATE]='create' | |
168 | [NAMES]='activate deactivate inspect authenticate remove lock unlock' | |
169 | [NAME]='update passwd' | |
170 | [RESIZE]='resize' | |
171 | [WITH]='with' | |
172 | ) | |
173 | ||
174 | for ((i=0; i < COMP_CWORD; i++)); do | |
175 | if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then | |
176 | verb=${COMP_WORDS[i]} | |
177 | break | |
178 | fi | |
179 | done | |
180 | ||
36ec0268 | 181 | if [[ -z ${verb-} ]]; then |
3a9692dd ZJS |
182 | comps=${VERBS[*]} |
183 | elif __contains_word "$verb" ${VERBS[NAME]}; then | |
184 | comps=$(__get_homes) | |
185 | elif __contains_word "$verb" ${VERBS[NAMES]}; then | |
186 | comps=$(__get_homes) | |
187 | elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[CREATE]} ${VERBS[RESIZE]}; then | |
188 | comps=$(__get_homes) | |
189 | elif __contains_word "$verb" ${VERBS[WITH]}; then | |
190 | comps=$(__get_homes) | |
191 | fi | |
192 | ||
193 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
194 | return 0 | |
195 | } | |
196 | ||
197 | complete -F _homectl homectl |