-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjson-glib-format
62 lines (48 loc) · 1.58 KB
/
json-glib-format
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/hint/bash -efu
#
# Bash programmable completion rules for json-glib-format(1)
#
# Copyright (C) 2019 Denis Ollier
#
# This script is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
_json_glib_format()
{
local cur prev words cword
_init_completion || return # requires bash-completion >= 1.90 (2011-11-03)
#
# Get full completion context
#
local indent prettify
local i length
length=${#words[@]}
# Skip the last word if it is the one being completed
((cword == length - 1)) && [ "${cur}" ] && ((length--))
for ((i = 0; i < length; i++)); do
case ${words[i]} in
'-h'|'--help') return;; # No completion for -h/--help
'-i'|'--indent-spaces') indent=1;;
'-p'|'--prettify') prettify=1;;
esac
done
#
# Generate smart completions
#
case ${prev} in
'-i'|'--indent-spaces')
COMPREPLY=($(compgen -W "{0..5} '...'" -- "${cur}"))
return
;;
esac
# Fallback to suggesting possible completions
local suggests
((${#words[@]} == 2)) && suggests+=('-h' '--help')
((!indent)) && suggests+=('-i' '--indent-spaces')
((!prettify)) && suggests+=('-p' '--prettify')
COMPREPLY=($(compgen -W '"${suggests[@]}"' -- "${cur}"))
COMPREPLY+=($(compgen -f -- "${cur}"))
}
complete -o nosort -F _json_glib_format json-glib-format
# vi: set ft=sh et sw=4 ts=4: