Move dataurisrc element from -bad
[platform/upstream/gstreamer.git] / data / completions / gst-launch-1.0
1 # GStreamer
2 # Copyright (C) 2015 Mathieu Duponchelle <mathieu.duponchelle@opencreed.com>
3 #
4 # bash/zsh completion support for gst-launch
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_launch_all_arguments ()
35 {
36         COMPREPLY=( $(compgen -W "$(gst-launch-1.0 --help-all | grep -oh '[[:graph:]]*--[[:graph:]]*' | cut -d'=' -f1)" -- $cur) )
37 }
38
39 _gst_complete_compatible_elements ()
40 {
41         COMPREPLY=( $(compgen -W "$($_GST_HELPER --compatible-with $previous_element)" -- $cur) )
42 }
43
44 _gst_complete_all_elements ()
45 {
46         COMPREPLY=( $(compgen -W "$($_GST_HELPER -l)" -- $cur) )
47 }
48
49 _gst_complete_element_properties ()
50 {
51         COMPREPLY=( $(compgen -W "$($_GST_HELPER --element-properties $previous_element)" -- $cur) )
52 }
53
54 _gstlaunch___exclude_ () { _gst_mandatory_argument; }
55
56 _gst_launch_main ()
57 {
58         local i=1 command function_exists previous_element have_previous_element=0 completion_func
59
60         while [[ $i -ne $COMP_CWORD ]];
61                 do
62                         local var
63                         var="${COMP_WORDS[i]}"
64                         if [[ "$var" == "--"* ]]
65                         then
66                                 command="$var"
67                         fi
68                 i=$(($i+1))
69                 done
70
71         i=1
72         while [[ $i -ne $COMP_CWORD ]];
73                 do
74                         local var
75                         var="${COMP_WORDS[i]}"
76
77                         if [[ "$var" == "--"* ]]
78                         then
79                                 i=$(($i+1))
80                                 continue
81                         fi
82
83                         $(gst-inspect-1.0 --exists $var)
84                         if [ $? -eq 0 ]
85                         then
86                                 previous_element="$var"
87                                 have_previous_element=1
88                         fi
89                 i=$(($i+1))
90                 done
91
92         if [[ "$command" == "--gst"* ]]; then
93                 completion_func="_${command//-/_}"
94         else
95                 completion_func="_gstlaunch_${command//-/_}"
96         fi
97
98         # Seems like bash doesn't like "exclude" in function names
99         if [[ "$completion_func" == "_gstlaunch___exclude" ]]
100         then
101                 completion_func="_gstlaunch___exclude_"
102         fi
103
104         declare -f $completion_func >/dev/null 2>&1
105
106         function_exists=$?
107
108         if [[ "$cur" == "--"* ]]; then
109                 _gst_launch_all_arguments
110         elif [ $function_exists -eq 0 ]
111         then
112                 $completion_func
113         elif [ $have_previous_element -ne 0 ] && [[ "$prev" == "!" ]]
114         then
115                 _gst_complete_compatible_elements
116         elif [ $have_previous_element -ne 0 ]
117         then
118                 _gst_complete_element_properties
119         else
120                 _gst_complete_all_elements
121         fi
122 }
123
124 _gst_launch_func_wrap ()
125 {
126         local cur prev
127         cur="${COMP_WORDS[COMP_CWORD]}"
128         prev="${COMP_WORDS[COMP_CWORD-1]}"
129         $1
130 }
131
132 # Setup completion for certain functions defined above by setting common
133 # variables and workarounds.
134 # This is NOT a public function; use at your own risk.
135 _gst_launch_complete ()
136 {
137         local wrapper="__launch_wrap${2}"
138         eval "$wrapper () { _gst_launch_func_wrap $2 ; }"
139         complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
140                 || complete -o default -o nospace -F $wrapper $1
141 }
142
143 _gst_launch_complete gst-launch-1.0 _gst_launch_main