1 # This file is part of systemd.
3 # Copyright 2010 Ran Benita
5 # systemd is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation; either version 2.1 of the License, or
8 # (at your option) any later version.
10 # systemd is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
19 systemctl --full --no-legend "$@"
24 for w in $*; do [[ $w = $word ]] && return 0; done
28 __filter_units_by_property () {
29 local property=$1 value=$2 ; shift 2
32 IFS=$'\n' read -rd '' -a props < \
33 <(__systemctl show --property "$property" -- "${units[@]}")
34 for ((i=0; $i < ${#units[*]}; i++)); do
35 if [[ "${props[i]}" = "$property=$value" ]]; then
36 printf "%s\n" "${units[i]}"
41 __get_all_units () { __systemctl list-units --all \
42 | { while read -r a b; do printf "%s\n" "$a"; done; }; }
43 __get_active_units () { __systemctl list-units \
44 | { while read -r a b; do printf "%s\n" "$a"; done; }; }
45 __get_inactive_units () { __systemctl list-units --all \
46 | { while read -r a b c d; do [[ $c == "inactive" ]] && printf "%s\n" "$a"; done; }; }
47 __get_failed_units () { __systemctl list-units \
48 | { while read -r a b c d; do [[ $c == "failed" ]] && printf "%s\n" "$a"; done; }; }
49 __get_enabled_units () { __systemctl list-unit-files \
50 | { while read -r a b c ; do [[ $b == "enabled" ]] && printf "%s\n" "$a"; done; }; }
51 __get_disabled_units () { __systemctl list-unit-files \
52 | { while read -r a b c ; do [[ $b == "disabled" ]] && printf "%s\n" "$a"; done; }; }
53 __get_masked_units () { __systemctl list-unit-files \
54 | { while read -r a b c ; do [[ $b == "masked" ]] && printf "%s\n" "$a"; done; }; }
57 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
61 [STANDALONE]='--all -a --defaults --fail --ignore-dependencies --failed --force -f --full --global
62 --help -h --no-ask-password --no-block --no-legend --no-pager --no-reload --no-wall
63 --order --require --quiet -q --privileged -P --system --user --version --runtime'
64 [ARG]='--host -H --kill-mode --kill-who --property -p --signal -s --type -t --root'
67 if __contains_word "$prev" ${OPTS[ARG]}; then
70 comps=$(compgen -A signal)
73 comps='automount device mount path service snapshot socket swap target timer'
76 comps='all control main'
79 comps='control-group process'
82 comps=$(compgen -A directory -- "$cur" )
86 comps=$(compgen -A hostname)
92 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
97 if [[ "$cur" = -* ]]; then
98 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
103 [ALL_UNITS]='is-active is-failed is-enabled status show mask preset'
104 [ENABLED_UNITS]='disable reenable'
105 [DISABLED_UNITS]='enable'
106 [FAILED_UNITS]='reset-failed'
107 [STARTABLE_UNITS]='start'
108 [STOPPABLE_UNITS]='stop condstop kill try-restart condrestart'
109 [ISOLATABLE_UNITS]='isolate'
110 [RELOADABLE_UNITS]='reload condreload reload-or-try-restart force-reload'
111 [RESTARTABLE_UNITS]='restart reload-or-restart'
112 [MASKED_UNITS]='unmask'
115 [ENVS]='set-environment unset-environment'
116 [STANDALONE]='daemon-reexec daemon-reload default dot dump
117 emergency exit halt hibernate hybrid-sleep kexec list-jobs
118 list-units list-unit-files poweroff reboot rescue
119 show-environment suspend'
120 [NAME]='snapshot load'
124 for ((i=0; $i <= $COMP_CWORD; i++)); do
125 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
126 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
127 verb=${COMP_WORDS[i]}
132 if [[ -z $verb ]]; then
135 elif __contains_word "$verb" ${VERBS[ALL_UNITS]}; then
136 comps=$( __get_all_units )
138 elif __contains_word "$verb" ${VERBS[ENABLED_UNITS]}; then
139 comps=$( __get_enabled_units )
141 elif __contains_word "$verb" ${VERBS[DISABLED_UNITS]}; then
142 comps=$( __get_disabled_units )
144 elif __contains_word "$verb" ${VERBS[STARTABLE_UNITS]}; then
145 comps=$( __filter_units_by_property CanStart yes \
146 $( __get_inactive_units \
147 | while read -r line; do \
148 [[ "$line" =~ \.(device|snapshot)$ ]] || printf "%s\n" "$line"; \
151 elif __contains_word "$verb" ${VERBS[RESTARTABLE_UNITS]}; then
152 comps=$( __filter_units_by_property CanStart yes \
154 | while read -r line; do \
155 [[ "$line" =~ \.(device|snapshot|socket|timer)$ ]] || printf "%s\n" "$line"; \
158 elif __contains_word "$verb" ${VERBS[STOPPABLE_UNITS]}; then
159 comps=$( __filter_units_by_property CanStop yes \
160 $( __get_active_units ) )
162 elif __contains_word "$verb" ${VERBS[RELOADABLE_UNITS]}; then
163 comps=$( __filter_units_by_property CanReload yes \
164 $( __get_active_units ) )
166 elif __contains_word "$verb" ${VERBS[ISOLATABLE_UNITS]}; then
167 comps=$( __filter_units_by_property AllowIsolate yes \
168 $( __get_all_units ) )
170 elif __contains_word "$verb" ${VERBS[FAILED_UNITS]}; then
171 comps=$( __get_failed_units )
173 elif __contains_word "$verb" ${VERBS[MASKED_UNITS]}; then
174 comps=$( __get_masked_units )
176 elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[NAME]}; then
179 elif __contains_word "$verb" ${VERBS[JOBS]}; then
180 comps=$( __systemctl list-jobs | { while read -r a b; do printf "%s\n" "$a"; done; } )
182 elif __contains_word "$verb" ${VERBS[SNAPSHOTS]}; then
183 comps=$( __systemctl list-units --type snapshot --full --all \
184 | { while read -r a b; do printf "%s\n" "$a"; done; } )
186 elif __contains_word "$verb" ${VERBS[ENVS]}; then
187 comps=$( __systemctl show-environment \
188 | while read -r line; do printf "%s\n" "${line%%=*}=";done )
191 elif __contains_word "$verb" ${VERBS[FILE]}; then
192 comps=$( compgen -A file -- "$cur" )
196 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
199 complete -F _systemctl systemctl
201 __get_all_sessions () { loginctl list-sessions | { while read -r a b; do printf "%s\n" "$a"; done; } ; }
202 __get_all_users () { loginctl list-users | { while read -r a b; do printf "%s\n" "$b"; done; } ; }
203 __get_all_seats () { loginctl list-seats | { while read -r a b; do printf "%s\n" "$a"; done; } ; }
206 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
210 [STANDALONE]='--all -a --help -h --no-pager --privileged -P --version'
211 [ARG]='--host -H --kill-who --property -p --signal -s'
214 if __contains_word "$prev" ${OPTS[ARG]}; then
217 comps=$(compgen -A signal)
223 comps=$(compgen -A hostname)
229 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
234 if [[ "$cur" = -* ]]; then
235 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
240 [SESSIONS]='session-status show-session activate lock-session unlock-session terminate-session kill-session'
241 [USERS]='user-status show-user enable-linger disable-linger terminate-user kill-user'
242 [SEATS]='seat-status show-seat terminate-seat'
243 [STANDALONE]='list-sessions list-users list-seats flush-devices'
247 for ((i=0; $i <= $COMP_CWORD; i++)); do
248 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
249 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
250 verb=${COMP_WORDS[i]}
255 if [[ -z $verb ]]; then
258 elif __contains_word "$verb" ${VERBS[SESSIONS]}; then
259 comps=$( __get_all_sessions )
261 elif __contains_word "$verb" ${VERBS[USERS]}; then
262 comps=$( __get_all_users )
264 elif __contains_word "$verb" ${VERBS[SEATS]}; then
265 comps=$( __get_all_seats )
267 elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
270 elif __contains_word "$verb" ${VERBS[ATTACH]}; then
271 if [[ $prev = $verb ]]; then
272 comps=$( __get_all_seats )
274 comps=$(compgen -A file -- "$cur" )
279 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
282 complete -F _loginctl loginctl
284 __journal_fields=(MESSAGE{,_ID} PRIORITY CODE_{FILE,LINE,FUNC}
285 ERRNO SYSLOG_{FACILITY,IDENTIFIER,PID} COREDUMP_EXE
286 _{P,U,G}ID _COMM _EXE _CMDLINE
287 _AUDIT_{SESSION,LOGINUID}
288 _SYSTEMD_{CGROUP,SESSION,UNIT,OWNER_UID}
289 _SELINUX_CONTEXT _SOURCE_REALTIME_TIMESTAMP
290 _{BOOT,MACHINE}_ID _HOSTNAME _TRANSPORT
291 _KERNEL_{DEVICE,SUBSYSTEM}
292 _UDEV_{SYSNAME,DEVNODE,DEVLINK}
293 __CURSOR __{REALTIME,MONOTONIC}_TIMESTAMP)
296 local field_vals= cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
298 [STANDALONE]='-a --all --full
299 -b --this-boot --disk-usage -f --follow --header
300 -h --help -l --local --new-id128 -m --merge --no-pager
301 --no-tail -q --quiet --setup-keys --this-boot --verify
302 --version --list-catalog --update-catalog'
303 [ARG]='-D --directory -F --field -o --output -u --unit'
304 [ARGUNKNOWN]='-c --cursor --interval -n --lines -p --priority --since --until
308 if __contains_word "$prev" ${OPTS[ARG]} ${OPTS[ARGUNKNOWN]}; then
311 comps=$(compgen -d -- "$cur")
315 comps='short short-monotonic verbose export json cat'
318 comps=${__journal_fields[*]}
321 comps=$(journalctl -F '_SYSTEMD_UNIT')
327 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
331 if [[ $cur = -* ]]; then
332 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
334 elif [[ $cur = *=* ]]; then
335 mapfile -t field_vals < <(journalctl -F "${prev%=}" 2>/dev/null)
336 COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "${cur#=}") )
337 elif [[ $prev = '=' ]]; then
338 mapfile -t field_vals < <(journalctl -F "${COMP_WORDS[COMP_CWORD-2]}" 2>/dev/null)
339 COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "$cur") )
342 COMPREPLY=( $(compgen -W '${__journal_fields[*]}' -S= -- "$cur") )
345 complete -F _journalctl journalctl
349 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
350 local OPTS='-h --help --version --no-pager --no-legend -o --output -F --field'
357 if __contains_word "$prev" '--output -o'; then
358 comps=$( compgen -A file -- "$cur" )
360 elif __contains_word "$prev" '--FIELD -F'; then
361 comps=$( compgen -W '${__journal_fields[*]}' -- "$cur" )
362 elif [[ $cur = -* ]]; then
364 elif __contains_word "$prev" ${VERBS[*]} &&
365 ! __contains_word ${COMP_WORDS[COMP_CWORD-2]} '--output -o -F --field'; then
367 COMPREPLY=( $(compgen -W '${__journal_fields[*]}' -S= -- "$cur") )
369 elif [[ $cur = *=* ]]; then
370 mapfile -t field_vals < <(systemd-coredumpctl -F "${prev%=}" 2>/dev/null)
371 COMPREPLY=( $(compgen -W '${field_vals[*]}' -- "${cur#=}") )
373 elif [[ $prev = '=' ]]; then
374 mapfile -t field_vals < <(systemd-coredumpctl -F "${COMP_WORDS[COMP_CWORD-2]}" 2>/dev/null)
375 comps=${field_vals[*]}
377 for ((i=0; i <= COMP_CWORD; i++)); do
378 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then
379 verb=${COMP_WORDS[i]}
384 if [[ -z $verb ]]; then
386 elif __contains_word "$verb" ${VERBS[LIST]} ${VERBS[DUMP]}; then
391 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
394 complete -F _coredumpctl systemd-coredumpctl
398 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
399 local OPTS='-h --help --version --adjust-system-clock --no-pager
400 --no-ask-password -H --host'
402 if __contains_word "$prev" $OPTS; then
408 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
412 if [[ $cur = -* ]]; then
413 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
418 [BOOLEAN]='set-local-rtc set-ntp'
419 [STANDALONE]='status set-time list-timezones'
420 [TIMEZONES]='set-timezone'
424 for ((i=0; i <= COMP_CWORD; i++)); do
425 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then
426 verb=${COMP_WORDS[i]}
431 if [[ -z $verb ]]; then
433 elif __contains_word "$verb" ${VERBS[BOOLEAN]}; then
435 elif __contains_word "$verb" ${VERBS[TIMEZONES]}; then
436 comps=$(command timedatectl list-timezones)
437 elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[TIME]}; then
441 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
444 complete -F _timedatectl timedatectl
448 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
449 local OPTS='-h --help --version --no-convert --no-pager --no-ask-password
452 if __contains_word "$prev" $OPTS; then
458 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
462 if [[ $cur = -* ]]; then
463 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
468 [STANDALONE]='status list-locales list-keymaps'
469 [LOCALES]='set-locale'
470 [KEYMAPS]='set-keymap'
471 [X11]='set-x11-keymap'
474 for ((i=0; i <= COMP_CWORD; i++)); do
475 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then
476 verb=${COMP_WORDS[i]}
481 if [[ -z $verb ]]; then
483 elif __contains_word "$verb" ${VERBS[LOCALES]}; then
484 comps=$(command localectl list-locales)
485 elif __contains_word "$verb" ${VERBS[KEYMAPS]}; then
486 comps=$(command localectl list-keymaps)
487 elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[X11]}; then
491 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
494 complete -F _localectl localectl
498 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
499 local OPTS='-h --help --version --transient --static --pretty
500 --no-ask-password -H --host'
502 if [[ $cur = -* ]]; then
503 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
508 [STANDALONE]='status'
509 [ICONS]='set-icon-name'
510 [NAME]='set-hostname'
513 for ((i=0; i <= COMP_CWORD; i++)); do
514 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then
515 verb=${COMP_WORDS[i]}
520 if [[ -z $verb ]]; then
522 elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[ICONS]} ${VERBS[NAME]}; then
526 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
529 complete -F _hostnamectl hostnamectl
531 __get_all_sysdevs() {
532 local -a devs=(/sys/bus/*/devices/*/ /sys/class/*/*/)
533 printf '%s\n' "${devs[@]%/}"
538 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
539 local OPTS='-h --help --version --debug'
548 [TESTBUILTIN]='test-builtin'
552 for ((i=0; $i <= $COMP_CWORD; i++)); do
553 if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
554 ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
555 verb=${COMP_WORDS[i]}
560 if [[ -z $verb && $cur = -* ]]; then
561 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
565 if [[ -z $verb ]]; then
568 elif __contains_word "$verb" ${VERBS[INFO]}; then
569 if [[ $cur = -* ]]; then
570 comps='--help --query= --path= --name= --root --attribute-walk --export-db --cleanup-db'
572 comps=$( __get_all_sysdevs )
575 elif __contains_word "$verb" ${VERBS[TRIGGER]}; then
576 comps='--help --verbose --dry-run --type= --action= --subsystem-match=
577 --subsystem-nomatch= --attr-match= --attr-nomatch= --property-match=
578 --tag-match= --sysname-match= --parent-match='
580 elif __contains_word "$verb" ${VERBS[SETTLE]}; then
581 comps='--help --timeout= --seq-start= --seq-end= --exit-if-exists= --quiet'
583 elif __contains_word "$verb" ${VERBS[CONTROL]}; then
584 comps='--help --exit --log-priority= --stop-exec-queue --start-exec-queue
585 --reload --property= --children-max= --timeout='
587 elif __contains_word "$verb" ${VERBS[MONITOR]}; then
588 comps='--help --kernel --udev --property --subsystem-match= --tag-match='
590 elif __contains_word "$verb" ${VERBS[HWDB]}; then
591 comps='--help --update --test='
593 elif __contains_word "$verb" ${VERBS[TEST]}; then
594 if [[ $cur = -* ]]; then
595 comps='--help --action='
597 comps=$( __get_all_sysdevs )
600 elif __contains_word "$verb" ${VERBS[TESTBUILTIN]}; then
601 comps='blkid btrfs firmware hwdb input_id kmod net_id path_id usb_id uaccess'
604 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
607 complete -F _udevadm udevadm