]>
Commit | Line | Data |
---|---|---|
abdab4f6 | 1 | # systemd-cgls(1) completion -*- shell-script -*- |
7059062c | 2 | # SPDX-License-Identifier: LGPL-2.1+ |
abdab4f6 TA |
3 | # |
4 | # This file is part of systemd. | |
5 | # | |
abdab4f6 TA |
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 | |
17 | # along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
18 | ||
19 | __contains_word() { | |
843cfcb1 ZJS |
20 | local w word=$1; shift |
21 | for w in "$@"; do | |
22 | [[ $w = "$word" ]] && return | |
23 | done | |
abdab4f6 TA |
24 | } |
25 | ||
26 | __get_machines() { | |
843cfcb1 | 27 | local a b |
e2268fa4 | 28 | machinectl list --full --no-legend --no-pager | { while read a b; do echo " $a"; done; }; |
abdab4f6 TA |
29 | } |
30 | ||
82ebb6ba | 31 | __get_units_have_cgroup() { |
843cfcb1 ZJS |
32 | systemctl $1 list-units | { |
33 | while read -r a b c d; do | |
34 | [[ $c == "active" && ${a##*.} =~ (service|socket|mount|swap|slice|scope) ]] && echo " $a" | |
35 | done | |
36 | }; | |
82ebb6ba YW |
37 | } |
38 | ||
abdab4f6 | 39 | _systemd_cgls() { |
843cfcb1 ZJS |
40 | local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]} |
41 | local i verb comps | |
abdab4f6 | 42 | |
843cfcb1 ZJS |
43 | local -A OPTS=( |
44 | [STANDALONE]='-h --help --version --all -l --full -k --no-pager' | |
45 | [ARG]='-M --machine -u --unit --user-unit' | |
46 | ) | |
abdab4f6 | 47 | |
843cfcb1 | 48 | _init_completion || return |
abdab4f6 | 49 | |
843cfcb1 ZJS |
50 | if __contains_word "$prev" ${OPTS[ARG]}; then |
51 | case $prev in | |
52 | --machine|-M) | |
53 | comps=$( __get_machines ) | |
54 | ;; | |
55 | --unit|-u) | |
56 | comps=$( __get_units_have_cgroup --system ) | |
57 | ;; | |
58 | --user-unit) | |
59 | comps=$( __get_units_have_cgroup --user ) | |
60 | ;; | |
61 | esac | |
62 | COMPREPLY=( $(compgen -W '$comps' -- "$cur") ) | |
63 | return 0 | |
64 | fi | |
abdab4f6 | 65 | |
843cfcb1 | 66 | COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") ) |
abdab4f6 TA |
67 | } |
68 | ||
69 | complete -F _systemd_cgls systemd-cgls |