hostnamectl revision a72d698d0d9ff9c158155b44cdc77376df31a317
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# hostnamectl(1) completion -*- shell-script -*-
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl#
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# This file is part of systemd.
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl#
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl# Copyright 2010 Ran Benita
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl#
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#
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#
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
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl__contains_word () {
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner local w word=$1; shift
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner for w in "$@"; do
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner [[ $w = "$word" ]] && return
a72d698d0d9ff9c158155b44cdc77376df31a317Dave Reisner done
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl}
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl
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
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl --no-ask-password -H --host'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl if [[ $cur = -* ]]; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl return 0
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl fi
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl local -A VERBS=(
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl [STANDALONE]='status'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl [ICONS]='set-icon-name'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl [NAME]='set-hostname'
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl 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 break
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl fi
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl done
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl if [[ -z $verb ]]; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps=${VERBS[*]}
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl elif __contains_word "$verb" ${VERBS[STANDALONE]} ${VERBS[ICONS]} ${VERBS[NAME]}; then
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl comps=''
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl fi
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl return 0
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl}
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Biebl
d611dadcc74db10ba533ee6859308f5fc505aee1Michael Bieblcomplete -F _hostnamectl hostnamectl