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