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