2 # Copyright (C) 2015 Mathieu Duponchelle <mathieu.duponchelle@opencreed.com>
4 # bash/zsh completion support for ges-launch
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.
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.
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.
21 HELPERDIR="${BASH_SOURCE[0]%/*}/../helpers"
23 if [[ ! -d "$HELPERDIR" ]]; then
24 HELPERDIR="$(pkg-config --variable=bashhelpersdir gstreamer-1.0)"
26 HELPERDIR=`cd "$HELPERDIR"; pwd`
33 GES_COMMAND_LIST="ges-launch-1.0 help | grep '^ +' | cut -d' ' -f3"
35 _ges___inspect_action_type ()
37 COMPREPLY=( $(compgen -W "$(ges-launch-1.0 --inspect-action-type | grep '^[^ ]' | cut -d':' -f2)" -- $cur) )
42 COMPREPLY=( $(compgen -W "audio video audio+video" -- $cur) )
45 _ges___set_scenario () {
46 COMPREPLY=( $(compgen -W "*.scenario $(gst-validate-1.0 -l | awk '$0=$2' FS=[ RS=])" -- $cur) )
50 COMPREPLY=( $(compgen -W "*.xges" -- $cur) )
54 COMPREPLY=( $(compgen -W "file://" -- $cur) )
58 COMPREPLY=( $(compgen -W "$($HELPER --klass=Sink --sinkcaps='audio/x-raw')" -- $cur) )
62 COMPREPLY=( $(compgen -W "$($HELPER --klass=Sink --sinkcaps='video/x-raw')" -- $cur) )
66 if [[ "$prev" == "$command" ]];
68 _gst_mandatory_argument
70 COMPREPLY=( $(compgen -W "duration= inpoint= start= layer= $($GES_COMMAND_LIST)" -- $cur) )
75 if [[ "$prev" == "$command" ]];
77 _gst_mandatory_argument
79 COMPREPLY=( $(compgen -W "duration= inpoint= start= layer= $($GES_COMMAND_LIST)" -- $cur) )
84 if [[ "$prev" == "$command" ]];
86 _gst_mandatory_argument
88 COMPREPLY=( $(compgen -W "duration= start= layer= $($GES_COMMAND_LIST)" -- $cur) )
92 _ges_list_options () {
93 _gst_all_arguments ges-launch-1.0
96 _ges_list_commands () {
97 COMPREPLY=( $(compgen -W "$($GES_COMMAND_LIST)" -- $cur) )
100 _ges_list_properties () {
103 if [[ "$real_command" == "" ]]
105 _gst_mandatory_argument
106 elif [[ "$real_command" == "+clip" ]]
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" ]]
111 COMPREPLY=( $(compgen -W "set-alpha set-posx set-posy set-width set-height set-volume set-mute" -- $cur) )
112 elif [[ "$real_command" == "+effect" ]]
115 effect_bin_description="${effect_bin_description//\"/ }"
116 array=(${effect_bin_description//!/ })
117 for i in "${array[@]}"; do
118 props=("$($HELPER --element-properties $i)")
121 COMPREPLY+=( $(compgen -W "set-$j" -- $cur) )
125 _gst_mandatory_argument
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; }
141 [[ "$e" == "$1" ]] && return 0;
148 local i=1 c=1 command function_exists completion_func commands real_command effect_bin_description
150 commands=($(ges-launch-1.0 help all | egrep '^ +'))
152 effect_bin_description=""
154 if [[ "$cur" == "=" ]]; then
155 _gst_mandatory_argument
159 while [[ $i -ne $COMP_CWORD ]];
162 var="${COMP_WORDS[i]}"
163 if [[ "$var" == "--"* ]]
166 elif containsElement "$var" "${commands[@]}";
170 if [[ "$var" == "+effect" ]]
172 effect_bin_description="${COMP_WORDS[i+1]}"
178 if [[ "$command" == "--gst"* ]]; then
179 completion_func="_${command//-/_}"
181 completion_func="_ges_${command//-/_}"
182 completion_func="${completion_func//+/}"
185 declare -f $completion_func >/dev/null 2>&1
189 if [[ "$cur" == "-"* ]]; then
191 elif [[ "$cur" == "+"* ]]; then
193 elif [[ "$cur" == "="* ]]
195 _gst_mandatory_argument
196 elif [[ "$cur" == "set-"* ]]
199 elif [ $function_exists -eq 0 ]
210 cur="${COMP_WORDS[COMP_CWORD]}"
211 prev="${COMP_WORDS[COMP_CWORD-1]}"
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.
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
231 __ges_complete ges-launch-1.0 __ges_main