]>
Commit | Line | Data |
---|---|---|
1 | # shellcheck shell=bash | |
2 | # homectl(1) completion -*- shell-script -*- | |
3 | # SPDX-License-Identifier: LGPL-2.1-or-later | |
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 | |
18 | # along with systemd; If not, see <https://www.gnu.org/licenses/>. | |
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 -A -N -T' | |
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 | |
97 | --luks-pbkdf-force-iterations | |
98 | --luks-pbkdf-time-cost | |
99 | --luks-pbkdf-memory-cost | |
100 | --luks-pbkdf-parallel-threads | |
101 | --luks-sector-size | |
102 | --nosuid | |
103 | --nodev | |
104 | --noexec | |
105 | --cifs-domain | |
106 | --cifs-user-name | |
107 | --cifs-service | |
108 | --stop-delay | |
109 | --kill-processes | |
110 | --auto-login | |
111 | -b --blob | |
112 | --avatar | |
113 | --login-background | |
114 | --session-launcher | |
115 | --session-type | |
116 | --key-name | |
117 | --seize | |
118 | --match' | |
119 | ) | |
120 | ||
121 | if __contains_word "$prev" ${OPTS[ARG]}; then | |
122 | case $prev in | |
123 | --host|-H) | |
124 | comps=$(compgen -A hostname) | |
125 | ;; | |
126 | --machine|-M) | |
127 | comps=$( __get_machines ) | |
128 | ;; | |
129 | --identity|--image-path|--avatar|--login-background) | |
130 | comps=$(compgen -A file -- "$cur" ) | |
131 | compopt -o filenames | |
132 | ;; | |
133 | --json) | |
134 | comps='pretty short off' | |
135 | ;; | |
136 | --export-format) | |
137 | comps='full stripped minimal' | |
138 | ;; | |
139 | --locked|--enforce-password-policy|--password-change-now|--luks-discard|--luks-offline-discard|--nosuid|--nodev|--noexec|--kill-processes|--auto-login) | |
140 | comps='yes no' | |
141 | ;; | |
142 | -d|--home-dir|--skel|-b|--blob) | |
143 | comps=$(compgen -A directory -- "$cur" ) | |
144 | compopt -o dirnames | |
145 | ;; | |
146 | -G|--member-of) | |
147 | comps=$(compgen -A group -- "$cur" ) | |
148 | ;; | |
149 | --shell) | |
150 | comps=$(cat /etc/shells) | |
151 | ;; | |
152 | --fs-type) | |
153 | comps='btrfs ext4 xfs' | |
154 | ;; | |
155 | --cifs-user-name) | |
156 | comps=$(compgen -A user -- "$cur" ) | |
157 | ;; | |
158 | --language) | |
159 | comps=$(localectl list-locales 2>/dev/null) | |
160 | ;; | |
161 | --session-launcher) | |
162 | comps=$(find /usr/share/{x,wayland-}sessions/ -type f -name '*.desktop' -exec basename {} .desktop \; 2>/dev/null | sort -u) | |
163 | ;; | |
164 | --session-type) | |
165 | comps='wayland x11 tty' | |
166 | ;; | |
167 | esac | |
168 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
169 | return 0 | |
170 | fi | |
171 | ||
172 | if [[ "$cur" = -* ]]; then | |
173 | COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) | |
174 | return 0 | |
175 | fi | |
176 | ||
177 | local -A VERBS=( | |
178 | [STANDALONE]='list lock-all register unregister adopt' | |
179 | [CREATE]='create' | |
180 | [NAMES]='activate deactivate inspect authenticate remove lock unlock' | |
181 | [NAME]='update passwd' | |
182 | [RESIZE]='resize' | |
183 | [WITH]='with' | |
184 | ) | |
185 | ||
186 | for ((i=0; i < COMP_CWORD; i++)); do | |
187 | if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then | |
188 | verb=${COMP_WORDS[i]} | |
189 | break | |
190 | fi | |
191 | done | |
192 | ||
193 | if [[ -z ${verb-} ]]; then | |
194 | comps=${VERBS[*]} | |
195 | elif __contains_word "$verb" ${VERBS[NAME]}; then | |
196 | comps=$(__get_homes) | |
197 | elif __contains_word "$verb" ${VERBS[NAMES]}; then | |
198 | comps=$(__get_homes) | |
199 | elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[CREATE]} ${VERBS[RESIZE]}; then | |
200 | comps=$(__get_homes) | |
201 | elif __contains_word "$verb" ${VERBS[WITH]}; then | |
202 | comps=$(__get_homes) | |
203 | fi | |
204 | ||
205 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
206 | return 0 | |
207 | } | |
208 | ||
209 | complete -F _homectl homectl |