-#!/usr/bin/env bash
-
-bashcomp=$(pkg-config --variable=prefix bash-completion
- )/share/bash-completion/bash_completion
-[ -f $bashcomp ] && . $bashcomp ||
-{ [ -f /etc/bash_completion ] && . /etc/bash_completion; }
+#!/bin/bash
. $(dirname "$0")/../../tools/gstreamer-completion
ret=0
COMP_CWORD=$(( ${#COMP_WORDS[*]} - 1 ))
COMP_LINE="${COMP_WORDS[*]}"
COMP_POINT=${#COMP_LINE}
-
- while [[ -n "$1" ]]; do expected+=("$1"); shift; done
+ expected=(); while [[ -n "$1" ]]; do expected+=("$1"); shift; done
printf "test_gst_inspect_completion: '${COMP_WORDS[*]}'... "
_gst_inspect
}
# test_gst_inspect_completion <command line to complete> -- <expected completions>
-test_gst_inspect_completion '' -- --version --gst-debug-level= coreelements fakesrc
+test_gst_inspect_completion '' -- --version --gst-debug-level coreelements fakesrc
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-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 coreel -- coreelements
test_gst_inspect_completion fake -- fakesrc fakesink
test_gst_inspect_completion --version --gst-debug-level = 2 fake -- fakesrc fakesink
COMP_CWORD=$(( ${#COMP_WORDS[*]} - 1 ))
COMP_LINE="${COMP_WORDS[*]}"
COMP_POINT=${#COMP_LINE}
- while [[ -n "$1" ]]; do expected+=("$1"); shift; done
+ expected=(); while [[ -n "$1" ]]; do expected+=("$1"); shift; done
printf "test_gst_launch_completion: '${COMP_WORDS[*]}'... "
_gst_launch
}
# test_gst_launch_completion <command line to complete> -- <expected completions>
-test_gst_launch_completion '' -- --eos-on-shutdown --gst-debug-level= fakesrc fakesink
+test_gst_launch_completion '' -- --eos-on-shutdown --gst-debug-level fakesrc fakesink
test_gst_launch_completion --mes -- --messages
-test_gst_launch_completion --gst-debug-le -- --gst-debug-level=
-test_gst_launch_completion --gst-debug-level -- --gst-debug-level=
+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 fak -- fakesrc fakesink
test_gst_launch_completion --messages fak -- fakesrc fakesink
words=(gst-launch)
while [[ "$1" != -- ]]; do words+=("$1"); shift; done; shift
cword=$(( ${#words[*]} - 1 ))
+ cur="${words[cword]}"
local xcurtype="$1" xoption="$2" xelement="$3" xproperty="$4"
printf "test_gst_launch_parse: '${words[*]}'... "
test_gst_launch_parse '' -- option-or-element '' '' ''
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 fak -- element '' '' ''
test_gst_launch_parse --messages fak -- element '' '' ''
_gst_version=1.0
_gst_inspect() {
- local cur prev words cword split
- _init_completion -n : -s || return
+ local cur cword prev words
+ _gst_init_completion
+ [[ "$cur" == "=" ]] && cur=
+
_gst_common_options || return
COMPREPLY=( $(compgen \
- -W "$(_parse_help gst-inspect-$_gst_version --help-all) \
+ -W "$(_gst_parse_help gst-inspect-$_gst_version) \
$(_gst_plugins) $(_gst_elements)" \
-- "$cur") )
[[ $COMPREPLY == *= ]] && compopt -o nospace 2>/dev/null
_gst_launch() {
local cur cword prev words
- _init_completion -n : || return
-
+ _gst_init_completion
local curtype option element property
_gst_launch_parse
_gst_common_options || return
complete -o default -F _gst_launch gst-launch-$_gst_version
_gst_common_options() {
- if [[ -v curtype && -v option ]]; then # Called from _gst_launch
+ if [[ -n "$curtype" ]]; then # Called from _gst_launch
[[ $curtype == optionval ]] || return 0
else # Called from _gst_inspect
local option="$prev"
_gst_launch_compgen() {
case $curtype in
- option|option-or-element)
+ option)
compgen \
- -W "$(_parse_help gst-launch-$_gst_version --help-all)" \
- -- "$cur"
- ;;& # test next pattern too.
- element|option-or-element)
+ -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" ;;
# ($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
-# by calling _init_completion.
+# $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.
*) 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
+}