ges-launch: Add support for +test-clip
[platform/upstream/gstreamer.git] / data / completions / ges-launch-1.0
1 # GStreamer
2 # Copyright (C) 2015 Mathieu Duponchelle <mathieu.duponchelle@opencreed.com>
3 #
4 # bash/zsh completion support for ges-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 HELPERDIR="${BASH_SOURCE[0]%/*}/../helpers"
22
23 if [[ ! -d "$HELPERDIR" ]]; then
24         HELPERDIR="$(pkg-config --variable=helpersdir gstreamer-1.0)"
25 else
26         HELPERDIR=`cd "$HELPERDIR"; pwd`
27 fi
28
29 # Common definitions
30 . "$HELPERDIR"/gst
31
32 HELPER="$HELPERDIR/gst-completion-helper-1.0"
33
34 _ges___inspect_action_type ()
35 {
36         COMPREPLY=( $(compgen -W "$(ges-launch-1.0 --inspect-action-type | grep '^[^ ]' | cut -d':' -f2)" -- $cur) )
37 }
38
39 _ges___track_types ()
40 {
41         COMPREPLY=( $(compgen -W "audio video audio+video" -- $cur) )
42 }
43
44 _ges___set_scenario () {
45         COMPREPLY=( $(compgen -W "*.scenario $(gst-validate-1.0 -l | awk '$0=$2' FS=[ RS=])" -- $cur) )
46 }
47
48 _ges___load () {
49         COMPREPLY=( $(compgen -W "*.xges" -- $cur) )
50 }
51
52 _ges___outputuri () {
53         COMPREPLY=( $(compgen -W "file://" -- $cur) )
54 }
55
56 _ges___audiosink () {
57         COMPREPLY=( $(compgen -W "$($HELPER --klass=Sink --sinkcaps='audio/x-raw')" -- $cur) )
58 }
59
60 _ges___videosink () {
61         COMPREPLY=( $(compgen -W "$($HELPER --klass=Sink --sinkcaps='video/x-raw')" -- $cur) )
62 }
63
64 _ges_clip () {
65         if [[ "$prev" == "$command" ]];
66         then
67                 _gst_mandatory_argument
68         else
69                 COMPREPLY=( $(compgen -W "duration= inpoint= start= layer= $(ges-launch-1.0 help all | egrep '^  +')" -- $cur) )
70         fi
71 }
72
73 _ges_test_clip () {
74         if [[ "$prev" == "$command" ]];
75         then
76                 _gst_mandatory_argument
77         else
78                 COMPREPLY=( $(compgen -W "duration= inpoint= start= layer= $(ges-launch-1.0 help all | egrep '^  +')" -- $cur) )
79         fi
80 }
81
82 _ges_effect () {
83         if [[ "$prev" == "$command" ]];
84         then
85                 _gst_mandatory_argument
86         else
87                 COMPREPLY=( $(compgen -W "duration= start= layer= $(ges-launch-1.0 help all | egrep '^  +')" -- $cur) )
88         fi
89 }
90
91 _ges_list_options () {
92         COMPREPLY=( $(compgen -W "$(ges-launch-1.0 --help-all | grep -oh '[[:graph:]]*--[[:graph:]]*' | cut -d'=' -f1)" -- $cur) )
93 }
94
95 _ges_list_commands () {
96         COMPREPLY=( $(compgen -W "$(ges-launch-1.0 help all | egrep '^  +')" -- $cur) )
97 }
98
99 _ges_list_properties () {
100         local props
101
102         if [[ "$real_command" == "" ]]
103         then
104                 _gst_mandatory_argument
105         elif [[ "$real_command" == "+clip" ]]
106         then
107                 COMPREPLY=( $(compgen -W "set-alpha set-posx set-posy set-width set-height set-volume set-mute" -- $cur) )
108         elif [[ "$real_command" == "+test-clip" ]]
109         then
110                 COMPREPLY=( $(compgen -W "set-alpha set-posx set-posy set-width set-height set-volume set-mute" -- $cur) )
111         elif [[ "$real_command" == "+effect" ]]
112         then
113                 COMPREPLY=()
114                 effect_bin_description="${effect_bin_description//\"/ }"
115                 array=(${effect_bin_description//!/ })
116                 for i in "${array[@]}"; do
117                         props=("$($HELPER --element-properties $i)")
118                         for j in $props; do
119                                 j="${j//=/ }"
120                                 COMPREPLY+=( $(compgen -W "set-$j" -- $cur) )
121                         done
122                 done
123         else
124                 _gst_mandatory_argument
125         fi
126 }
127
128 _ges___exclude_ () { _gst_mandatory_argument; }
129 _ges___encoding_profile () { _gst_mandatory_argument; }
130 _ges___ges_sample_path () { _gst_mandatory_argument; }
131 _ges___ges_sample_path_recurse () { _gst_mandatory_argument; }
132 _ges___thumbnail () { _gst_mandatory_argument; }
133 _ges___repeat () { _gst_mandatory_argument; }
134 _ges___save () { _gst_mandatory_argument; }
135
136 containsElement () {
137         local e
138         for e in "${@:2}";
139         do
140                 [[ "$e" == "$1" ]] && return 0;
141         done
142         return 1
143 }
144
145 __ges_main ()
146 {
147         local i=1 c=1 command function_exists completion_func commands real_command effect_bin_description
148
149         commands=($(ges-launch-1.0 help all | egrep '^  +'))
150         real_command=""
151         effect_bin_description=""
152
153         if [[ "$cur" == "=" ]]; then
154                 _gst_mandatory_argument
155                 return
156         fi
157
158         while [[ $i -ne $COMP_CWORD ]];
159                 do
160                         local var
161                         var="${COMP_WORDS[i]}"
162                         if [[ "$var" == "--"* ]]
163                         then
164                                 command="$var"
165                         elif containsElement "$var" "${commands[@]}";
166                         then
167                                 real_command="$var"
168                                 command="$var"
169                                 if [[ "$var" == "+effect" ]]
170                                 then
171                                         effect_bin_description="${COMP_WORDS[i+1]}"
172                                 fi
173                         fi
174                 i=$[$i+1]
175                 done
176
177         if [[ "$command" == "--gst"* ]]; then
178                 completion_func="_${command//-/_}"
179         else
180                 completion_func="_ges_${command//-/_}"
181                 completion_func="${completion_func//+/}"
182         fi
183
184         declare -f $completion_func >/dev/null 2>&1
185
186         function_exists=$?
187
188         if [[ "$cur" == "-"* ]]; then
189                 _ges_list_options
190         elif [[ "$cur" == "+"* ]]; then
191                 _ges_list_commands
192         elif [[ "$cur" == "="* ]]
193         then
194                 _gst_mandatory_argument
195         elif [[ "$cur" == "set-"* ]]
196         then
197                 _ges_list_properties
198         elif [ $function_exists -eq 0 ]
199         then
200                 $completion_func
201         else
202                 _ges_list_commands
203         fi
204 }
205
206 __ges_func_wrap ()
207 {
208         local cur prev
209         cur="${COMP_WORDS[COMP_CWORD]}"
210         prev="${COMP_WORDS[COMP_CWORD-1]}"
211         $1
212 }
213
214 # Setup completion for certain functions defined above by setting common
215 # variables and workarounds.
216 # This is NOT a public function; use at your own risk.
217 __ges_complete ()
218 {
219         local wrapper="__ges_wrap${2}"
220         eval "$wrapper () { __ges_func_wrap $2 ; }"
221         complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
222                 || complete -o default -o nospace -F $wrapper $1
223 }
224
225 _ges ()
226 {
227         __ges_wrap__ges_main
228 }
229
230 __ges_complete ges-launch-1.0 __ges_main