• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2# Check for bash
3[ -z "$BASH_VERSION" ] && return
4
5####################################################################################################
6
7__gsettings() {
8  local choices coffset schemadir
9
10  if [ ${COMP_CWORD} -gt 2 ]; then
11      if [ ${COMP_WORDS[1]} = --schemadir ]; then
12	  # this complexity is needed to perform correct tilde expansion
13	  schemadir=$(eval "echo --schemadir ${COMP_WORDS[2]}")
14	  coffset=2
15      else
16	  coffset=0
17      fi
18  else
19      coffset=0
20  fi
21
22  case "$((${COMP_CWORD}-$coffset))" in
23    1)
24      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 '
25      ;;
26
27    2)
28      case "${COMP_WORDS[$(($coffset+1))]}" in
29	--schemadir)
30	  COMPREPLY=($(compgen -o dirnames -- ${COMP_WORDS[${COMP_CWORD}]}))
31	  return 0
32	  ;;
33
34        help)
35          choices=$'list-schemas\nlist-relocatable-schemas\nlist-keys\nlist-children\nlist-recursively\nget\nrange\nset\nreset\nreset-recursively\nwritable\nmonitor'
36          ;;
37        list-keys|list-children|list-recursively|reset-recursively)
38          choices="$(gsettings $schemadir list-schemas 2> /dev/null)"$'\n'"$(gsettings $schemadir list-relocatable-schemas 2> /dev/null | sed -e 's.$.:/.')"
39          ;;
40        list-schemas)
41          COMPREPLY=($(compgen -W "--print-paths" -- ${COMP_WORDS[${COMP_CWORD}]}))
42          return 0
43          ;;
44
45        get|range|set|reset|writable|monitor|describe)
46          choices="$(gsettings $schemadir list-schemas 2> /dev/null | sed -e 's.$. .')"$'\n'"$(gsettings $schemadir list-relocatable-schemas 2> /dev/null | sed -e 's.$.:/.')"
47          ;;
48      esac
49      ;;
50
51    3)
52      case "${COMP_WORDS[$(($coffset+1))]}" in
53        set)
54          choices="$(gsettings $schemadir list-keys ${COMP_WORDS[$(($coffset+2))]} 2> /dev/null | sed -e 's.$. .')"
55          ;;
56
57        get|range|reset|writable|monitor|describe)
58          choices="$(gsettings $schemadir list-keys ${COMP_WORDS[$(($coffset+2))]} 2> /dev/null)"
59          ;;
60      esac
61      ;;
62
63    4)
64      case "${COMP_WORDS[$(($coffset+2))]}" in
65        set)
66          range=($(gsettings $schemadir range ${COMP_WORDS[$(($coffset+2))]} ${COMP_WORDS[$(($coffset+3))]} 2> /dev/null))
67          case "${range[0]}" in
68            enum)
69              unset range[0]
70             ;;
71            *)
72              unset range
73             ;;
74          esac
75          local IFS=$'\n'
76          choices="${range[*]}"
77          ;;
78      esac
79      ;;
80  esac
81
82  local IFS=$'\n'
83  COMPREPLY=($(compgen -W "${choices}" -- "${COMP_WORDS[${COMP_CWORD}]}"))
84}
85
86####################################################################################################
87
88complete -o nospace -F __gsettings gsettings
89