]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
bash-completion: cgls: suggests units
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 10 Jan 2018 12:47:08 +0000 (21:47 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 10 Jan 2018 14:19:00 +0000 (23:19 +0900)
shell-completion/bash/systemd-cgls

index 0f579a6e67c6d9a481efdccbc277f206b3ecc8c4..34c7b9e67f15d0511491e702590f23c68c7663e4 100644 (file)
@@ -30,13 +30,21 @@ __get_machines() {
         machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
 }
 
+__get_units_have_cgroup() {
+        systemctl $1 list-units | {
+                while read -r a b c d; do
+                        [[ $c == "active" && ${a##*.} =~ (service|socket|mount|swap|slice|scope) ]] && echo " $a"
+                done
+        };
+}
+
 _systemd_cgls() {
         local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
         local i verb comps
 
         local -A OPTS=(
                [STANDALONE]='-h --help --version --all -l --full -k --no-pager'
-                      [ARG]='-M --machine'
+                      [ARG]='-M --machine -u --unit --user-unit'
         )
 
         _init_completion || return
@@ -46,6 +54,12 @@ _systemd_cgls() {
                         --machine|-M)
                                 comps=$( __get_machines )
                         ;;
+                        --unit|-u)
+                                comps=$( __get_units_have_cgroup --system )
+                        ;;
+                        --user-unit)
+                                comps=$( __get_units_have_cgroup --user )
+                        ;;
                 esac
                 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
                 return 0