d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# hostnamectl(1) completion -*- shell-script -*-
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# This file is part of systemd.
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# Copyright 2010 Ran Benita
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# systemd is free software; you can redistribute it and/or modify it
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# under the terms of the GNU Lesser General Public License as published by
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# the Free Software Foundation; either version 2.1 of the License, or
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# (at your option) any later version.
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# systemd is distributed in the hope that it will be useful, but
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# WITHOUT ANY WARRANTY; without even the implied warranty of
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# General Public License for more details.
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# You should have received a copy of the GNU Lesser General Public License
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# along with systemd; If not, see <http://www.gnu.org/licenses/>.
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl__contains_word () {
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner local w word=$1; shift
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner for w in "$@"; do
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner [[ $w = "$word" ]] && return
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl_hostnamectl() {
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl local i verb comps
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl local OPTS='-h --help --version --transient --static --pretty
b4f91f2ba354c16dc23111cc231010c975c717a2Carlos Morata Castillo --no-ask-password -H --host --machine'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl if [[ $cur = -* ]]; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl local -A VERBS=(
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl [STANDALONE]='status'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl [ICONS]='set-icon-name'
101297247832e58844d5235f3b30aaa23b52338cEvgeny Vereshchagin [NAME]='set-hostname set-deployment set-location'
1ed774956406941d4812a3fb4493d2915f130f12Zbigniew Jędrzejewski-Szmek [CHASSIS]='set-chassis'
3ce09b7da2eb8b888066468663b2b5c81a05a03cZbigniew Jędrzejewski-Szmek for ((i=0; i < COMP_CWORD; i++)); do
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]}; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl verb=${COMP_WORDS[i]}
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl if [[ -z $verb ]]; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps=${VERBS[*]}
1ed774956406941d4812a3fb4493d2915f130f12Zbigniew Jędrzejewski-Szmek elif __contains_word "$verb" ${VERBS[CHASSIS]}; then
25fa306ed58b0b7fe30ca9be37c66a7b3b2de70eLennart Poettering comps='desktop laptop server tablet handset watch embedded vm container'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[ICONS]} ${VERBS[NAME]}; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Bieblcomplete -F _hostnamectl hostnamectl