]> git.ipfire.org Git - thirdparty/systemd.git/blob - shell-completion/bash/systemd-path
Merge pull request #1426 from poettering/log-syntax
[thirdparty/systemd.git] / shell-completion / bash / systemd-path
1 # systemd-path(1) completion -*- shell-script -*-
2 #
3 # This file is part of systemd.
4 #
5 # systemd is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU Lesser General Public License as published by
7 # the Free Software Foundation; either version 2.1 of the License, or
8 # (at your option) any later version.
9 #
10 # systemd is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public License
16 # along with systemd; If not, see <http://www.gnu.org/licenses/>.
17
18 __contains_word () {
19 local w word=$1; shift
20 for w in "$@"; do
21 [[ $w = "$word" ]] && return
22 done
23 return 1
24 }
25
26 __get_names() {
27 systemd-path | { while IFS=: read -r a b; do echo " $a"; done; }
28 }
29
30 _systemd_path() {
31 local comps
32 local cur=${COMP_WORDS[COMP_CWORD]} prev=${COMP_WORDS[COMP_CWORD-1]}
33 local -A OPTS=(
34 [STANDALONE]='-h --help --version'
35 [ARG]='--suffix'
36 )
37
38 _init_completion || return
39
40 if __contains_word "$prev" ${OPTS[ARG]}; then
41 case $prev in
42 --suffix)
43 comps=''
44 ;;
45 esac
46 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
47 return 0
48 fi
49
50 if [[ "$cur" = -* ]]; then
51 COMPREPLY=( $(compgen -W '${OPTS[*]}' -- "$cur") )
52 return 0
53 fi
54
55 comps=$( __get_names )
56 COMPREPLY=( $(compgen -W '$comps' -- "$cur") )
57 return 0
58 }
59
60 complete -F _systemd_path systemd-path