1 # Bash tab-completion for GStreamer. -*- shell-script -*-
2 # Put this in /etc/bash_completion.d/
6 local cur cword prev words
8 [[ "$cur" == "=" ]] && cur=
9 [[ "$cur" =~ -.*=*$ ]] && prev="${cur%%=*}" cur="${cur#*=}"
11 _gst_common_options || return
13 COMPREPLY=( $(compgen \
14 -W "$(_gst_parse_help gst-inspect-$_gst_version) \
15 $(_gst_plugins) $(_gst_elements)" \
17 [[ $COMPREPLY == *= ]] && compopt -o nospace 2>/dev/null
19 complete -F _gst_inspect gst-inspect-1.0
22 local _gst_version=1.0
23 local cur cword prev words
25 local curtype option element property
27 _gst_common_options || return
29 COMPREPLY=( $(_gst_launch_compgen) )
30 [[ $COMPREPLY == *= ]] && compopt -o nospace 2>/dev/null
32 complete -o default -F _gst_launch gst-launch-1.0
34 _gst_common_options() {
35 if [[ -n "$curtype" ]]; then # Called from _gst_launch
36 [[ $curtype == optionval ]] || return 0
37 else # Called from _gst_inspect
43 COMPREPLY=( $(compgen -W "0 1 2 3 4 5" -- "$cur") );;
44 --gst-debug) # TODO: comma-separated list of category_name:level pairs.
46 --gst-plugin-path) # TODO: support multiple (colon-separated) paths.
47 COMPREPLY=( $(compgen -d -- "$cur") );;
48 --gst-plugin-load) # TODO: comma-separated list of plugins (files?).
52 return 1 # No need to attempt further completions.
55 _gst_launch_compgen() {
59 -W "$(_gst_parse_help gst-launch-$_gst_version)" \
62 compgen -W "$(_gst_elements)" -- "$cur" ;;
65 -W "$(_gst_parse_help gst-launch-$_gst_version) \
70 -o|--output) compgen -f -- "$cur" ;;
71 --exclude) ;; # TODO: comma-separated list of status information types.
74 compgen -W '!' -- "$cur" ;;
76 compgen -W "$(_gst_properties $element) ! " -- "$cur" ;;
78 compgen -W "$(_gst_property_values $element $property)" -- "$cur" ;;
83 gst-inspect-$_gst_version 2>/dev/null |
84 grep -v 'Total count' |
85 awk -F': +' '{print $1}' |
90 gst-inspect-$_gst_version 2>/dev/null |
91 grep -v 'Total count' |
92 awk -F': +' '{print $2}'
97 gst-inspect-$_gst_version "$element" 2>/dev/null |
98 sed -n '/^Element Properties:$/,$ p' |
99 awk '/^ [a-z]/ { print $1 "=" }'
102 _gst_property_values() {
103 local element=$1 property=$2
104 gst-inspect-$_gst_version $element 2>/dev/null |
106 /^Element Properties:\$/ { inproperties = 1; next; }
107 inproperties && /^ $property / { inproperty = 1; next; }
108 inproperty && /^ *Boolean/ { printf \"true\nfalse\n\"; exit; }
109 inproperty && /^ *Enum/ { inenum = 1; next; }
110 inenum && /^ *\([0-9]+\): / { print \$2; next; }
111 inproperty && /^ [a-z]/ { exit; }"
114 # Walks over $words, sets $curtype to the string:
116 # 'option' if $cur is an option or flag like "-a" or "--abc".
117 # 'optionval' if $cur is the value of an option
118 # (which will be set in $option).
119 # 'element' if $cur is a GStreamer element name.
120 # '!' if $cur is '!'.
121 # 'property' if $cur is the name of a property of a GStreamer element
122 # (which will be set in $element).
123 # 'propertyval' if $cur is the value of an element's property
124 # (which will be set in $element and $property, respectively).
126 # ($cur is the word currently being completed.)
128 # Before calling this function make sure that $curtype, $option, $element and
129 # $property are local, and that $cur, $cword and $words have been initialised.
131 # See test cases in tests/misc/test-gstreamer-completion.sh in the
132 # gstreamer source repository.
134 _gst_launch_parse() {
136 curtype= i=1 state=start
137 while [[ $i -le $cword ]]; do
139 # Note that COMP_WORDBREAKS by default includes "=" and ":".
140 case "$state,$next" in
141 start,-*=*) curtype=optionval option="${next%%=*}" state=start;;
142 start,-*) curtype=option option="$next" state=option;;
143 start,) curtype=option-or-element;;
144 start,*) curtype=element element="$next" state=element;;
145 option,=) curtype=optionval state=option=;;
146 option,*) _gst_takes_arg "$option" &&
147 curtype=optionval state=start ||
148 # re-evaluate without incrementing i:
149 { curtype= state=start; continue; }
151 option=,*) curtype=optionval state=start;;
152 element,\!) curtype='!' state='!';;
153 \!,*) curtype=element element="$next" state=element;;
155 curtype=propertyval property="${next%=}" state=property=;;
157 curtype=propertyval property="${next%%=*}" state=element;;
158 element,*) curtype=property property="$next" state=property;;
159 property,=) curtype=propertyval state=property=;;
160 property=,*) curtype=propertyval state=element;;
169 -o|--output|--gst-debug-level|--gst-debug) true;;
170 --gst-plugin-path|--gst-plugin-load|--exclude) true;;
176 $1 --help-all 2>&1 | grep -Eo -e '--[a-z-]+'
179 _gst_init_completion() {
180 if type _get_comp_words_by_ref &>/dev/null; then
181 # Available since bash-completion 1.2
182 _get_comp_words_by_ref cur cword prev words
184 # bash-completion not installed or too old. Use bash's raw facilities.
185 # This won't complete properly if the cursor is in the middle of a
187 cur="${COMP_WORDS[COMP_CWORD]}"
188 prev="${COMP_WORDS[COMP_CWORD-1]}"
190 words=("${COMP_WORDS[@]}")