2 # Copyright (C) 2015 Mathieu Duponchelle <mathieu.duponchelle@opencreed.com>
4 # bash/zsh completion support for gst-inspect
6 # This library is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU Library General Public
8 # License as published by the Free Software Foundation; either
9 # version 2 of the License, or (at your option) any later version.
11 # This library is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # Library General Public License for more details.
16 # You should have received a copy of the GNU Library General Public
17 # License along with this library; if not, write to the
18 # Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19 # Boston, MA 02110-1301, USA.
21 _GST_HELPERDIR="${BASH_SOURCE[0]%/*}/../helpers"
23 if [[ ! -d "$_GST_HELPERDIR" ]]; then
24 _GST_HELPERDIR="$(pkg-config --variable=helpersdir gstreamer-1.0)"
26 _GST_HELPERDIR=`cd "$_GST_HELPERDIR"; pwd`
30 . "$_GST_HELPERDIR"/gst
32 _GST_HELPER="$_GST_HELPERDIR/gst-completion-helper-1.0"
34 _gst_inspect_all_arguments ()
36 COMPREPLY=( $(compgen -W "$(gst-inspect-1.0 --help-all | grep -oh '[[:graph:]]*--[[:graph:]]*' | cut -d'=' -f1)" -- $cur) )
39 _gst_inspect_all_elements ()
41 COMPREPLY=( $(compgen -W "$($_GST_HELPER -l)" -- $cur) )
44 _gstinspect___atleast_version () { _gst_mandatory_argument; }
46 _gstinspect___exists ()
48 _gst_inspect_all_elements
53 local i=1 command function_exists completion_func
55 while [[ $i -ne $COMP_CWORD ]];
58 var="${COMP_WORDS[i]}"
59 if [[ "$var" == "--"* ]]
66 if [[ "$command" == "--gst"* ]]; then
67 completion_func="_${command//-/_}"
69 completion_func="_gstinspect_${command//-/_}"
72 declare -f $completion_func >/dev/null 2>&1
76 if [[ "$cur" == "--"* ]]; then
77 _gst_inspect_all_arguments
78 elif [ $function_exists -eq 0 ]
82 _gst_inspect_all_elements
86 _gst_inspect_func_wrap ()
89 cur="${COMP_WORDS[COMP_CWORD]}"
90 prev="${COMP_WORDS[COMP_CWORD-1]}"
94 # Setup completion for certain functions defined above by setting common
95 # variables and workarounds.
96 # This is NOT a public function; use at your own risk.
97 _gst_inspect_complete ()
99 local wrapper="__inspect_wrap${2}"
100 eval "$wrapper () { _gst_inspect_func_wrap $2 ; }"
101 complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
102 || complete -o default -o nospace -F $wrapper $1
105 _gst_inspect_complete gst-inspect-1.0 __inspect_main