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