completions: prefix shell functions with _gst

+ To make it more difficult for them to conflict in the
  global namespace.

https://bugzilla.gnome.org/show_bug.cgi?id=744877#c21
This commit is contained in:
Mathieu Duponchelle 2015-03-18 14:37:11 +01:00
parent 038c0a1360
commit c72abb2737
2 changed files with 22 additions and 22 deletions

View file

@ -31,12 +31,12 @@ fi
HELPER="$HELPERDIR/gst-completion-helper-1.0" HELPER="$HELPERDIR/gst-completion-helper-1.0"
_inspect_all_arguments () _gst_inspect_all_arguments ()
{ {
COMPREPLY=( $(compgen -W "$(gst-inspect-1.0 --help-all | grep -oh '[[:graph:]]*--[[:graph:]]*' | cut -d'=' -f1)" -- $cur) ) COMPREPLY=( $(compgen -W "$(gst-inspect-1.0 --help-all | grep -oh '[[:graph:]]*--[[:graph:]]*' | cut -d'=' -f1)" -- $cur) )
} }
_inspect_all_elements () _gst_inspect_all_elements ()
{ {
COMPREPLY=( $(compgen -W "$($HELPER -l)" -- $cur) ) COMPREPLY=( $(compgen -W "$($HELPER -l)" -- $cur) )
} }
@ -45,7 +45,7 @@ _gstinspect___atleast_version () { _mandatory__argument; }
_gstinspect___exists () _gstinspect___exists ()
{ {
_inspect_all_elements _gst_inspect_all_elements
} }
__inspect_main () __inspect_main ()
@ -74,16 +74,16 @@ __inspect_main ()
function_exists=$? function_exists=$?
if [[ "$cur" == "--"* ]]; then if [[ "$cur" == "--"* ]]; then
_inspect_all_arguments _gst_inspect_all_arguments
elif [ $function_exists -eq 0 ] elif [ $function_exists -eq 0 ]
then then
$completion_func $completion_func
else else
_inspect_all_elements _gst_inspect_all_elements
fi fi
} }
__inspect_func_wrap () _gst_inspect_func_wrap ()
{ {
local cur prev local cur prev
cur="${COMP_WORDS[COMP_CWORD]}" cur="${COMP_WORDS[COMP_CWORD]}"
@ -94,12 +94,12 @@ __inspect_func_wrap ()
# Setup completion for certain functions defined above by setting common # Setup completion for certain functions defined above by setting common
# variables and workarounds. # variables and workarounds.
# This is NOT a public function; use at your own risk. # This is NOT a public function; use at your own risk.
__inspect_complete () _gst_inspect_complete ()
{ {
local wrapper="__inspect_wrap${2}" local wrapper="__inspect_wrap${2}"
eval "$wrapper () { __inspect_func_wrap $2 ; }" eval "$wrapper () { _gst_inspect_func_wrap $2 ; }"
complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \ complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
|| complete -o default -o nospace -F $wrapper $1 || complete -o default -o nospace -F $wrapper $1
} }
__inspect_complete gst-inspect-1.0 __inspect_main _gst_inspect_complete gst-inspect-1.0 __inspect_main

View file

@ -31,29 +31,29 @@ fi
HELPER="$HELPERDIR/gst-completion-helper-1.0" HELPER="$HELPERDIR/gst-completion-helper-1.0"
_launch_all_arguments () _gst_launch_all_arguments ()
{ {
COMPREPLY=( $(compgen -W "$(gst-launch-1.0 --help-all | grep -oh '[[:graph:]]*--[[:graph:]]*' | cut -d'=' -f1)" -- $cur) ) COMPREPLY=( $(compgen -W "$(gst-launch-1.0 --help-all | grep -oh '[[:graph:]]*--[[:graph:]]*' | cut -d'=' -f1)" -- $cur) )
} }
_complete_compatible_elements () _gst_complete_compatible_elements ()
{ {
COMPREPLY=( $(compgen -W "$($HELPER --compatible-with $previous_element)" -- $cur) ) COMPREPLY=( $(compgen -W "$($HELPER --compatible-with $previous_element)" -- $cur) )
} }
_complete_all_elements () _gst_complete_all_elements ()
{ {
COMPREPLY=( $(compgen -W "$($HELPER -l)" -- $cur) ) COMPREPLY=( $(compgen -W "$($HELPER -l)" -- $cur) )
} }
_complete_element_properties () _gst_complete_element_properties ()
{ {
COMPREPLY=( $(compgen -W "$($HELPER --element-properties $previous_element)" -- $cur) ) COMPREPLY=( $(compgen -W "$($HELPER --element-properties $previous_element)" -- $cur) )
} }
_gstlaunch___exclude_ () { _mandatory__argument; } _gstlaunch___exclude_ () { _mandatory__argument; }
__launch_main () _gst_launch_main ()
{ {
local i=1 command function_exists previous_element have_previous_element=0 completion_func local i=1 command function_exists previous_element have_previous_element=0 completion_func
@ -106,22 +106,22 @@ __launch_main ()
function_exists=$? function_exists=$?
if [[ "$cur" == "--"* ]]; then if [[ "$cur" == "--"* ]]; then
_launch_all_arguments _gst_launch_all_arguments
elif [ $function_exists -eq 0 ] elif [ $function_exists -eq 0 ]
then then
$completion_func $completion_func
elif [ $have_previous_element -ne 0 ] && [[ "$prev" == "!" ]] elif [ $have_previous_element -ne 0 ] && [[ "$prev" == "!" ]]
then then
_complete_compatible_elements _gst_complete_compatible_elements
elif [ $have_previous_element -ne 0 ] elif [ $have_previous_element -ne 0 ]
then then
_complete_element_properties _gst_complete_element_properties
else else
_complete_all_elements _gst_complete_all_elements
fi fi
} }
__launch_func_wrap () _gst_launch_func_wrap ()
{ {
local cur prev local cur prev
cur="${COMP_WORDS[COMP_CWORD]}" cur="${COMP_WORDS[COMP_CWORD]}"
@ -132,12 +132,12 @@ __launch_func_wrap ()
# Setup completion for certain functions defined above by setting common # Setup completion for certain functions defined above by setting common
# variables and workarounds. # variables and workarounds.
# This is NOT a public function; use at your own risk. # This is NOT a public function; use at your own risk.
__launch_complete () _gst_launch_complete ()
{ {
local wrapper="__launch_wrap${2}" local wrapper="__launch_wrap${2}"
eval "$wrapper () { __launch_func_wrap $2 ; }" eval "$wrapper () { _gst_launch_func_wrap $2 ; }"
complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \ complete -o bashdefault -o default -o nospace -F $wrapper $1 2>/dev/null \
|| complete -o default -o nospace -F $wrapper $1 || complete -o default -o nospace -F $wrapper $1
} }
__launch_complete gst-launch-1.0 __launch_main _gst_launch_complete gst-launch-1.0 _gst_launch_main