bash-completion: cgls: suggests units

This commit is contained in:
Yu Watanabe 2018-01-10 21:47:08 +09:00
parent 7c3940f6ce
commit 82ebb6ba1f
1 changed files with 15 additions and 1 deletions

View 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