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