completions: remove last unnamespaced symbols.
[platform/upstream/gstreamer.git] / data / completions / gst-inspect-1.0
1 # GStreamer
2 # Copyright (C) 2015 Mathieu Duponchelle <mathieu.duponchelle@opencreed.com>
3 #
4 # bash/zsh completion support for gst-inspect
5 #
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.
10 #
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.
15 #
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.
20
21 _GST_HELPERDIR="${BASH_SOURCE[0]%/*}/../helpers"
22
23 if [[ ! -d "$_GST_HELPERDIR"  ]]; then
24         _GST_HELPERDIR="$(pkg-config --variable=helpersdir gstreamer-1.0)"
25 else
26         _GST_HELPERDIR=`cd "$_GST_HELPERDIR"; pwd`
27 fi
28
29 # Common definitions
30 . "$_GST_HELPERDIR"/gst
31
32 _GST_HELPER="$_GST_HELPERDIR/gst-completion-helper-1.0"
33
34 _gst_inspect_all_arguments ()
35 {
36         COMPREPLY=( $(compgen -W "$(gst-inspect-1.0 --help-all | grep -oh '[[:graph:]]*--[[:graph:]]*' | cut -d'=' -f1)" -- $cur) )
37 }
38
39 _gst_inspect_all_elements ()
40 {
41         COMPREPLY=( $(compgen -W "$($_GST_HELPER -l)" -- $cur) )
42 }
43
44 _gstinspect___atleast_version () { _gst_mandatory_argument; }
45
46 _gstinspect___exists ()
47 {
48         _gst_inspect_all_elements
49 }
50
51 __inspect_main ()
52 {
53         local i=1 command function_exists completion_func
54
55         while [[ $i -ne $COMP_CWORD ]];
56                 do
57                         local var
58                         var="${COMP_WORDS[i]}"
59                         if [[ "$var" == "--"* ]]
60                         then
61                                 command="$var"
62                         fi
63                 i=$(($i+1))
64                 done
65
66         if [[ "$command" == "--gst"* ]]; then
67                 completion_func="_${command//-/_}"
68         else
69                 completion_func="_gstinspect_${command//-/_}"
70         fi
71
72         declare -f $completion_func >/dev/null 2>&1
73
74         function_exists=$?
75
76         if [[ "$cur" == "--"* ]]; then
77                 _gst_inspect_all_arguments
78         elif [ $function_exists -eq 0 ]
79         then
80                 $completion_func
81         else
82                 _gst_inspect_all_elements
83         fi
84 }
85
86 _gst_inspect_func_wrap ()
87 {
88         local cur prev
89         cur="${COMP_WORDS[COMP_CWORD]}"
90         prev="${COMP_WORDS[COMP_CWORD-1]}"
91         $1
92 }
93
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 ()
98 {
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
103 }
104
105 _gst_inspect_complete gst-inspect-1.0 __inspect_main