-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgstreamer-completion
193 lines (177 loc) · 6.57 KB
/
gstreamer-completion
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# Bash tab-completion for GStreamer. -*- shell-script -*-
# Put this in /etc/bash_completion.d/
# https://raw.githubusercontent.com/drothlis/gstreamer/bash-completion-master/tools/gstreamer-completion
_gst_inspect() {
local _gst_version=1.0
local cur cword prev words
_gst_init_completion
[[ "$cur" == "=" ]] && cur=
[[ "$cur" =~ -.*=*$ ]] && prev="${cur%%=*}" cur="${cur#*=}"
_gst_common_options || return
COMPREPLY=( $(compgen \
-W "$(_gst_parse_help gst-inspect-$_gst_version) \
$(_gst_plugins) $(_gst_elements)" \
-- "$cur") )
[[ $COMPREPLY == *= ]] && compopt -o nospace 2>/dev/null
} &&
complete -F _gst_inspect gst-inspect-1.0
_gst_launch() {
local _gst_version=1.0
local cur cword prev words
_gst_init_completion
local curtype option element property
_gst_launch_parse
_gst_common_options || return
COMPREPLY=( $(_gst_launch_compgen) )
[[ $COMPREPLY == *= ]] && compopt -o nospace 2>/dev/null
} &&
complete -o default -F _gst_launch gst-launch-1.0
_gst_common_options() {
if [[ -n "$curtype" ]]; then # Called from _gst_launch
[[ $curtype == optionval ]] || return 0
else # Called from _gst_inspect
local option="$prev"
fi
case "$option" in
--gst-debug-level)
COMPREPLY=( $(compgen -W "0 1 2 3 4 5" -- "$cur") );;
--gst-debug) # TODO: comma-separated list of category_name:level pairs.
;;
--gst-plugin-path) # TODO: support multiple (colon-separated) paths.
COMPREPLY=( $(compgen -d -- "$cur") );;
--gst-plugin-load) # TODO: comma-separated list of plugins (files?).
;;
*) return 0;;
esac
return 1 # No need to attempt further completions.
}
_gst_launch_compgen() {
case $curtype in
option)
compgen \
-W "$(_gst_parse_help gst-launch-$_gst_version)" \
-- "$cur" ;;
element)
compgen -W "$(_gst_elements)" -- "$cur" ;;
option-or-element)
compgen \
-W "$(_gst_parse_help gst-launch-$_gst_version) \
$(_gst_elements)" \
-- "$cur" ;;
optionval)
case "$option" in
-o|--output) compgen -f -- "$cur" ;;
--exclude) ;; # TODO: comma-separated list of status information types.
esac ;;
\!)
compgen -W '!' -- "$cur" ;;
property)
compgen -W "$(_gst_properties $element) ! " -- "$cur" ;;
propertyval)
compgen -W "$(_gst_property_values $element $property)" -- "$cur" ;;
esac
}
_gst_plugins() {
gst-inspect-$_gst_version 2>/dev/null |
grep -v 'Total count' |
awk -F': +' '{print $1}' |
uniq
}
_gst_elements() {
gst-inspect-$_gst_version 2>/dev/null |
grep -v 'Total count' |
awk -F': +' '{print $2}'
}
_gst_properties() {
local element="$1"
gst-inspect-$_gst_version "$element" 2>/dev/null |
sed -n '/^Element Properties:$/,$ p' |
awk '/^ [a-z]/ { print $1 "=" }'
}
_gst_property_values() {
local element=$1 property=$2
gst-inspect-$_gst_version $element 2>/dev/null |
awk "
/^Element Properties:\$/ { inproperties = 1; next; }
inproperties && /^ $property / { inproperty = 1; next; }
inproperty && /^ *Boolean/ { printf \"true\nfalse\n\"; exit; }
inproperty && /^ *Enum/ { inenum = 1; next; }
inenum && /^ *\([0-9]+\): / { print \$2; next; }
inproperty && /^ [a-z]/ { exit; }"
}
# Walks over $words, sets $curtype to the string:
#
# 'option' if $cur is an option or flag like "-a" or "--abc".
# 'optionval' if $cur is the value of an option
# (which will be set in $option).
# 'element' if $cur is a GStreamer element name.
# '!' if $cur is '!'.
# 'property' if $cur is the name of a property of a GStreamer element
# (which will be set in $element).
# 'propertyval' if $cur is the value of an element's property
# (which will be set in $element and $property, respectively).
#
# ($cur is the word currently being completed.)
#
# Before calling this function make sure that $curtype, $option, $element and
# $property are local, and that $cur, $cword and $words have been initialised.
#
# See test cases in tests/misc/test-gstreamer-completion.sh in the
# gstreamer source repository.
#
_gst_launch_parse() {
local i next state
curtype= i=1 state=start
while [[ $i -le $cword ]]; do
next="${words[i]}"
# Note that COMP_WORDBREAKS by default includes "=" and ":".
case "$state,$next" in
start,-*=*) curtype=optionval option="${next%%=*}" state=start;;
start,-*) curtype=option option="$next" state=option;;
start,) curtype=option-or-element;;
start,*) curtype=element element="$next" state=element;;
option,=) curtype=optionval state=option=;;
option,*) _gst_takes_arg "$option" &&
curtype=optionval state=start ||
# re-evaluate without incrementing i:
{ curtype= state=start; continue; }
;;
option=,*) curtype=optionval state=start;;
element,\!) curtype='!' state='!';;
\!,*) curtype=element element="$next" state=element;;
element,*=)
curtype=propertyval property="${next%=}" state=property=;;
element,*=*)
curtype=propertyval property="${next%%=*}" state=element;;
element,*) curtype=property property="$next" state=property;;
property,=) curtype=propertyval state=property=;;
property=,*) curtype=propertyval state=element;;
esac
i=$((i + 1))
done
cur="${cur#*=}"
}
_gst_takes_arg() {
case "$1" in
-o|--output|--gst-debug-level|--gst-debug) true;;
--gst-plugin-path|--gst-plugin-load|--exclude) true;;
*) false;;
esac
}
_gst_parse_help() {
$1 --help-all 2>&1 | grep -Eo -e '--[a-z-]+'
}
_gst_init_completion() {
if type _get_comp_words_by_ref &>/dev/null; then
# Available since bash-completion 1.2
_get_comp_words_by_ref cur cword prev words
else
# bash-completion not installed or too old. Use bash's raw facilities.
# This won't complete properly if the cursor is in the middle of a
# word.
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
cword=$COMP_CWORD
words=("${COMP_WORDS[@]}")
fi
}