tools/gstreamer-completion: Complete option & property values on bash 3.2

Bash 3's completion doesn't split words by characters in
COMP_WORDBREAKS. In particular it doesn't split at "=" signs. Now
_gst_launch_parse handles both bash 3 and 4 format of COMP_WORDS.

Note that "${cur%%=*}" means cur's value with the longest possible match
of "=*" deleted from the end; "${cur#*=}" means cur's value with the
shortest possible match of "*=" deleted from the beginning. See
http://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html

Regardless of the version of bash running the unit tests, I can test for
both behaviours because the unit test populates COMP_WORDS manually. So
this tests the bash 3 behaviour:

    test_gst_inspect_completion --gst-debug-level=4

and this tests the bash 4 behaviour:

    test_gst_inspect_completion --gst-debug-level = 4
This commit is contained in:
David Rothlisberger 2012-12-21 18:13:53 +00:00 committed by Stefan Sauer
parent f586e34a50
commit 5d6635f9b4
2 changed files with 28 additions and 1 deletions

View file

@ -39,9 +39,12 @@ test_gst_inspect_completion --ver -- --version
test_gst_inspect_completion --gst-debug-le -- --gst-debug-level
test_gst_inspect_completion --gst-debug-level '' -- 0 1 2 3 4 5
test_gst_inspect_completion --gst-debug-level = -- 0 1 2 3 4 5
test_gst_inspect_completion --gst-debug-level= -- 0 1 2 3 4 5
test_gst_inspect_completion --gst-debug-level=4 -- 4
test_gst_inspect_completion coreel -- coreelements
test_gst_inspect_completion fake -- fakesrc fakesink
test_gst_inspect_completion --version --gst-debug-level = 2 fake -- fakesrc fakesink
test_gst_inspect_completion --gst-debug-level=2 fake -- fakesrc fakesink
test_gst_launch_completion() {
@ -66,13 +69,27 @@ test_gst_launch_completion --mes -- --messages
test_gst_launch_completion --gst-debug-le -- --gst-debug-level
test_gst_launch_completion --gst-debug-level '' -- 0 1 2 3 4 5
test_gst_launch_completion --gst-debug-level = -- 0 1 2 3 4 5
test_gst_launch_completion --gst-debug-level= -- 0 1 2 3 4 5
test_gst_launch_completion --gst-debug-level=4 -- 4
test_gst_launch_completion fak -- fakesrc fakesink
test_gst_launch_completion --messages fak -- fakesrc fakesink
test_gst_launch_completion --messages --eos-on-shutdown fak -- fakesrc
test_gst_launch_completion --gst-debug-level = 4 fak -- fakesrc
test_gst_launch_completion --gst-debug-level=4 fak -- fakesrc
test_gst_launch_completion fakesrc '' -- name= is-live= format= !
test_gst_launch_completion fakesrc is-live -- is-live=
test_gst_launch_completion fakesrc is-live = -- true false
test_gst_launch_completion fakesrc format = -- bytes time buffers percent
test_gst_launch_completion fakesrc format= -- bytes time buffers percent
test_gst_launch_completion fakesrc format=by -- bytes
test_gst_launch_completion fakesrc format= '' -- bytes time buffers percent
test_gst_launch_completion fakesrc format= by -- bytes
test_gst_launch_completion fakesrc is-live = true '' -- name= format= !
test_gst_launch_completion fakesrc is-live = true for -- format=
test_gst_launch_completion fakesrc is-live=true '' -- name= format= !
test_gst_launch_completion fakesrc is-live=true for -- format=
test_gst_launch_completion fakesrc is-live = true format = -- bytes time
test_gst_launch_completion fakesrc is-live=true format= -- bytes time
test_gst_launch_parse() {
@ -109,12 +126,16 @@ test_gst_launch_parse --mes -- option '' '' ''
test_gst_launch_parse --messages -- option '' '' ''
test_gst_launch_parse --gst-debug-level '' -- optionval --gst-debug-level '' ''
test_gst_launch_parse --gst-debug-level = -- optionval --gst-debug-level '' ''
test_gst_launch_parse --gst-debug-level= -- optionval --gst-debug-level '' ''
test_gst_launch_parse --gst-debug-level=5 -- optionval --gst-debug-level '' ''
test_gst_launch_parse fak -- element '' '' ''
test_gst_launch_parse --messages fak -- element '' '' ''
test_gst_launch_parse --gst-debug-level = 5 fak -- element '' '' ''
test_gst_launch_parse fakesrc '' -- property '' fakesrc ''
test_gst_launch_parse fakesrc is-l -- property '' fakesrc ''
test_gst_launch_parse fakesrc is-live = -- propertyval '' fakesrc is-live
test_gst_launch_parse fakesrc is-live= -- propertyval '' fakesrc is-live
test_gst_launch_parse fakesrc is-live=b -- propertyval '' fakesrc is-live
test_gst_launch_parse fakesrc is-live = true form -- property '' 'fakesrc' ''
test_gst_launch_parse fakesrc is-live = true ! -- ! '' '' ''
test_gst_launch_parse fakesrc is-live = true ! fakesi -- element '' '' ''

View file

@ -7,6 +7,7 @@ _gst_inspect() {
local cur cword prev words
_gst_init_completion
[[ "$cur" == "=" ]] && cur=
[[ "$cur" =~ -.*=*$ ]] && prev="${cur%%=*}" cur="${cur#*=}"
_gst_common_options || return
@ -137,6 +138,7 @@ _gst_launch_parse() {
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;;
@ -149,13 +151,17 @@ _gst_launch_parse() {
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=""
cur="${cur#*=}"
}
_gst_takes_arg() {