Debian Codegraph @

gio/completion/gsettings

raw
1 #
2 # Copyright 2010, 2012 Red Hat, Inc.
3 # Copyright 2010 Allison Karlitskaya
4 # Copyright 2011 Giovanni Campagna
5 #
6 # This library is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU Lesser General Public License as
8 # published by the Free Software Foundation; either version 2.1 of the
9 # licence, or (at your option) any later version.
10 #
11 # This is distributed in the hope that it will be useful, but WITHOUT
12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 # License for more details.
15 #
16 # You should have received a copy of the GNU Lesser General Public License
17 # along with this library; if not, see <http://www.gnu.org/licenses/>.
18 #
19 # SPDX-License-Identifier: LGPL-2.1-or-later
20
21 # shellcheck shell=bash
22
23 # Check for bash
24 [ -z "$BASH_VERSION" ] && return
25
26 ####################################################################################################
27
28 __gsettings() {
29 local choices coffset schemadir=() gsettings_binary
30 gsettings_binary="$1"
31
32 if [ "${COMP_CWORD}" -gt 2 ]; then
33 if [ "${COMP_WORDS[1]}" = --schemadir ]; then
34 # The eval complexity is needed to perform correct tilde expansion
35 # The array is needed to ensure we can keep it expanding to either zero
36 # or one option in the commands below, while keeping quoting correct.
37 # See https://www.shellcheck.net/wiki/SC2086
38 schemadir=("--schemadir" "$(eval "echo ${COMP_WORDS[2]}")")
39 coffset=2
40 else
41 coffset=0
42 fi
43 else
44 coffset=0
45 fi
46
47 case "$((COMP_CWORD-coffset))" in
48 1)
49 choices=$'--schemadir\n--version\nhelp \nlist-schemas\nlist-relocatable-schemas\nlist-keys \nlist-children \nlist-recursively \nget \nrange \nset \nreset \nreset-recursively \nwritable \nmonitor \ndescribe '
50 ;;
51
52 2)
53 case "${COMP_WORDS[$((coffset+1))]}" in
54 --schemadir)
55 # shellcheck disable=SC2207
56 COMPREPLY=($(compgen -o dirnames -- "${COMP_WORDS[${COMP_CWORD}]}"))
57 return 0
58 ;;
59
60 help)
61 choices=$'list-schemas\nlist-relocatable-schemas\nlist-keys\nlist-children\nlist-recursively\nget\nrange\nset\nreset\nreset-recursively\nwritable\nmonitor'
62 ;;
63 list-keys|list-children|list-recursively|reset-recursively)
64 choices="$("$gsettings_binary" "${schemadir[@]}" list-schemas 2> /dev/null)"$'\n'"$("$gsettings_binary" "${schemadir[@]}" list-relocatable-schemas 2> /dev/null | sed -e 's.$.:/.')"
65 ;;
66 list-schemas)
67 # shellcheck disable=SC2207
68 COMPREPLY=($(compgen -W "--print-paths" -- "${COMP_WORDS[${COMP_CWORD}]}"))
69 return 0
70 ;;
71
72 get|range|set|reset|writable|monitor|describe)
73 choices="$("$gsettings_binary" "${schemadir[@]}" list-schemas 2> /dev/null | sed -e 's.$. .')"$'\n'"$("$gsettings_binary" "${schemadir[@]}" list-relocatable-schemas 2> /dev/null | sed -e 's.$.:/.')"
74 ;;
75 esac
76 ;;
77
78 3)
79 case "${COMP_WORDS[$((coffset+1))]}" in
80 set)
81 choices="$("$gsettings_binary" "${schemadir[@]}" list-keys "${COMP_WORDS[$((coffset+2))]}" 2> /dev/null | sed -e 's.$. .')"
82 ;;
83
84 get|range|reset|writable|monitor|describe)
85 choices="$("$gsettings_binary" "${schemadir[@]}" list-keys "${COMP_WORDS[$((coffset+2))]}" 2> /dev/null)"
86 ;;
87 esac
88 ;;
89
90 4)
91 case "${COMP_WORDS[$((coffset+2))]}" in
92 set)
93 # shellcheck disable=SC2207
94 range=($("$gsettings_binary" "${schemadir[@]}" range "${COMP_WORDS[$((coffset+2))]}" "${COMP_WORDS[$((coffset+3))]}" 2> /dev/null))
95 case "${range[0]}" in
96 enum)
97 unset 'range[0]'
98 ;;
99 *)
100 unset range
101 ;;
102 esac
103 local IFS=$'\n'
104 choices="${range[*]}"
105 ;;
106 esac
107 ;;
108 esac
109
110 local IFS=$'\n'
111 # shellcheck disable=SC2207
112 COMPREPLY=($(compgen -W "${choices-}" -- "${COMP_WORDS[${COMP_CWORD}]}"))
113 }
114
115 ####################################################################################################
116
117 complete -o nospace -F __gsettings gsettings