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 HELPERDIR="${BASH_SOURCE[0]%/*}/../helpers"
23 if [[ ! -d "$HELPERDIR" ]]; then
24 HELPERDIR="$(pkg-config --variable=helpersdir gstreamer-1.0)"
26 HELPERDIR=`cd "$HELPERDIR"; pwd`
32 HELPER="$HELPERDIR/gst-completion-helper-1.0"
34 _inspect_all_arguments ()
36 COMPREPLY=( $(compgen -W "$(gst-inspect-1.0 --help-all | grep -oh '[[:graph:]]*--[[:graph:]]*' | cut -d'=' -f1)" -- $cur) )
39 _inspect_all_elements ()
41 COMPREPLY=( $(compgen -W "$($HELPER -l)" -- $cur) )
44 _gstinspect___atleast_version () { _mandatory__argument; }
46 _gstinspect___exists ()
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 _inspect_all_arguments
78 elif [ $function_exists -eq 0 ]
86 __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.
99 local wrapper="__inspect_wrap${2}"
100 eval "$wrapper () { __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 __inspect_complete gst-inspect-1.0 __inspect_main