abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen# systemd-cgls(1) completion -*- shell-script -*-
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen# This file is part of systemd.
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen# Copyright 2014 Thomas H.P. Andersen
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen# systemd is free software; you can redistribute it and/or modify it
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen# under the terms of the GNU Lesser General Public License as published by
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen# the Free Software Foundation; either version 2.1 of the License, or
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen# (at your option) any later version.
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen# systemd is distributed in the hope that it will be useful, but
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen# WITHOUT ANY WARRANTY; without even the implied warranty of
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen# General Public License for more details.
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen# You should have received a copy of the GNU Lesser General Public License
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen# along with systemd; If not, see <http://www.gnu.org/licenses/>.
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen__contains_word() {
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen local w word=$1; shift
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen for w in "$@"; do
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen [[ $w = "$word" ]] && return
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen__get_machines() {
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen machinectl list --no-legend --no-pager | { while read a b; do echo " $a"; done; };
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen local i verb comps
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen [STANDALONE]='-h --help --version --all -l --full -k --no-pager'
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen [ARG]='-M --machine'
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen _init_completion || return
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen if __contains_word "$prev" ${OPTS[ARG]}; then
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen comps=$( __get_machines )
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersen COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
abdab4f602745952030a37b1521cd0374d51d3eaThomas Hindoe Paaboel Andersencomplete -F _systemd_cgls systemd-cgls