e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin# networkctl(1) completion -*- shell-script -*-
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin# This file is part of systemd.
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin# systemd is free software; you can redistribute it and/or modify it
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin# under the terms of the GNU Lesser General Public License as published by
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin# the Free Software Foundation; either version 2.1 of the License, or
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin# (at your option) any later version.
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin# systemd is distributed in the hope that it will be useful, but
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin# WITHOUT ANY WARRANTY; without even the implied warranty of
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin# General Public License for more details.
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin# You should have received a copy of the GNU Lesser General Public License
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin# along with systemd; If not, see <http://www.gnu.org/licenses/>.
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin__contains_word () {
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin local w word=$1; shift
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin for w in "$@"; do
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin [[ $w = "$word" ]] && return
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin__get_links() {
b00c1cf9d61ccd9b0f7bc131f01d80bb5736af0dZbigniew Jędrzejewski-Szmek networkctl list --no-legend --no-pager --all | { while read -r a b c; do echo " $b"; done; };
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin_networkctl() {
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin local i verb comps
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin local -A OPTS=(
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin [STANDALONE]='-a --all -h --help --version --no-pager --no-legend'
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin local -A VERBS=(
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin [STANDALONE]='list lldp'
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin [LINKS]='status'
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin _init_completion || return
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin for ((i=0; i < COMP_CWORD; i++)); do
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin if __contains_word "${COMP_WORDS[i]}" ${VERBS[*]} &&
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin ! __contains_word "${COMP_WORDS[i-1]}" ${OPTS[ARG]}; then
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin verb=${COMP_WORDS[i]}
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin if [[ "$cur" = -* ]]; then
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin if [[ -z $verb ]]; then
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin comps=${VERBS[*]}
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin elif __contains_word "$verb" ${VERBS[STANDALONE]}; then
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin elif __contains_word "$verb" ${VERBS[LINKS]}; then
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin comps=$( __get_links )
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagin COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
e4f246b1b512c68260581c4976d2eb01cf7febdcEvgeny Vereshchagincomplete -F _networkctl networkctl