gstreamer/tools/gstreamer-completion

193 lines
6.5 KiB
Text
Raw Normal View History

tools/gstreamer-completion: Support gst-inspect, and gst-launch element properties Completes options like "--gst-debug-level" and the values of some of those options; completes gst-launch pipeline element names, property names, and even property values (for enum or boolean properties only). Doesn't complete all caps specifications, nor element names specified earlier in the pipeline with "name=...". The GStreamer version number is hard-coded into the completion script: This patch is off the master branch and has the version hard-coded as "1.0"; it needs to be updated if backported to the 0.10 branch. You could always create a "gstreamer-completion.in" that has the appropriate version inserted by "configure", but I'd rather not do that. The hard-coded version is consistent with the previous implementation of gstreamer-completion, which had the registry path hard-coded as ~/.gstreamer-1.0/registry.xml. Note that GStreamer 0.10 installs "gst-inspect" and "gst-inspect-0.10". "gst-inspect --help" only prints 4 flags (--help, --print, --gst-mm, gst-list-mm) whereas "gst-inspect-0.10 --help-all" prints the full list of flags. The same applies to "gst-launch" and "gst-launch-0.10". GStreamer 1.0 only installs "gst-inspect-1.0", not "gst-inspect". Requires bash 4; only tested with bash 4.2. Requires "bash-completion" (which you install with your system's package manager). Put this in /etc/bash_completion.d/ or in `pkg-config --variable=compatdir bash-completion`, where it will be loaded at the beginning of every new terminal session; or in `pgk-config --variable=completionsdir bash-completion`, renamed to match the name of the command it completes (e.g. "gst-launch-1.0", with an additional symlink named "gst-inspect-1.0"), where it will be autoloaded when needed. test-gstreamer-completion.sh is (for now) in tests/misc -- it might be worth creating "tests/check/tools", with all the necessary automake boilerplate, and moving test-gstreamer-completion.sh there, and have it run automatically with "make check". IF YOU'RE NEW TO BASH COMPLETION SCRIPTS ---------------------------------------- "complete -F _gst_launch gst-launch-1.0" means that bash will run the function "_gst_launch" to generate possible completions for the command "gst-launch-1.0". "_gst_launch" must return the possible completions in the array variable COMPREPLY. (Note on bash syntax: "V=(a b c)" assigns three elements to the array "V"). "compgen" prints a list of possible completions to standard output. Try it: compgen -W "abc1 abc2 def" -- "a" compgen -f -- "/" The last argument is the word currently being completed; compgen uses it to filter out the non-matching completions. We put "--" first, in case the word currently being completed starts with "-" or "--", so that it isn't treated as a flag to compgen. For the documentation of COMP_WORDS, COMP_CWORD, etc see http://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-COMP_005fCWORD-180 See also: * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html The bash-completion package provides the helper function "_init_completion" which populates variables "cur", "prev", and "words". See http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=blob;f=bash_completion;h=870811b4;hb=HEAD#l634 Note that by default, bash appends a space to the completed word. When the completion is "property=" we don't want a trailing space; calling "compopt -o nospace" modifies the currently-executing completion accordingly. See http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#index-compopt
2012-12-19 10:46:50 +00:00
# Bash tab-completion for GStreamer. -*- shell-script -*-
# Put this in /etc/bash_completion.d/
tools/gstreamer-completion: Support gst-inspect, and gst-launch element properties Completes options like "--gst-debug-level" and the values of some of those options; completes gst-launch pipeline element names, property names, and even property values (for enum or boolean properties only). Doesn't complete all caps specifications, nor element names specified earlier in the pipeline with "name=...". The GStreamer version number is hard-coded into the completion script: This patch is off the master branch and has the version hard-coded as "1.0"; it needs to be updated if backported to the 0.10 branch. You could always create a "gstreamer-completion.in" that has the appropriate version inserted by "configure", but I'd rather not do that. The hard-coded version is consistent with the previous implementation of gstreamer-completion, which had the registry path hard-coded as ~/.gstreamer-1.0/registry.xml. Note that GStreamer 0.10 installs "gst-inspect" and "gst-inspect-0.10". "gst-inspect --help" only prints 4 flags (--help, --print, --gst-mm, gst-list-mm) whereas "gst-inspect-0.10 --help-all" prints the full list of flags. The same applies to "gst-launch" and "gst-launch-0.10". GStreamer 1.0 only installs "gst-inspect-1.0", not "gst-inspect". Requires bash 4; only tested with bash 4.2. Requires "bash-completion" (which you install with your system's package manager). Put this in /etc/bash_completion.d/ or in `pkg-config --variable=compatdir bash-completion`, where it will be loaded at the beginning of every new terminal session; or in `pgk-config --variable=completionsdir bash-completion`, renamed to match the name of the command it completes (e.g. "gst-launch-1.0", with an additional symlink named "gst-inspect-1.0"), where it will be autoloaded when needed. test-gstreamer-completion.sh is (for now) in tests/misc -- it might be worth creating "tests/check/tools", with all the necessary automake boilerplate, and moving test-gstreamer-completion.sh there, and have it run automatically with "make check". IF YOU'RE NEW TO BASH COMPLETION SCRIPTS ---------------------------------------- "complete -F _gst_launch gst-launch-1.0" means that bash will run the function "_gst_launch" to generate possible completions for the command "gst-launch-1.0". "_gst_launch" must return the possible completions in the array variable COMPREPLY. (Note on bash syntax: "V=(a b c)" assigns three elements to the array "V"). "compgen" prints a list of possible completions to standard output. Try it: compgen -W "abc1 abc2 def" -- "a" compgen -f -- "/" The last argument is the word currently being completed; compgen uses it to filter out the non-matching completions. We put "--" first, in case the word currently being completed starts with "-" or "--", so that it isn't treated as a flag to compgen. For the documentation of COMP_WORDS, COMP_CWORD, etc see http://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-COMP_005fCWORD-180 See also: * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html The bash-completion package provides the helper function "_init_completion" which populates variables "cur", "prev", and "words". See http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=blob;f=bash_completion;h=870811b4;hb=HEAD#l634 Note that by default, bash appends a space to the completed word. When the completion is "property=" we don't want a trailing space; calling "compopt -o nospace" modifies the currently-executing completion accordingly. See http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#index-compopt
2012-12-19 10:46:50 +00:00
_gst_inspect() {
local _gst_version=1.0
tools/gstreamer-completion: Bash 3.2 compatibility fixes Compatible with bash 3.2; doesn't require the bash-completion package at all (though the easiest way to install this script is still to install bash-completion, and then drop this script into /etc/bash_completion.d). Note that bash 3 doesn't break COMP_WORDS according to characters in COMP_WORDBREAKS, so "property=val" looks like a single word, so this won't complete property values (on bash 3). Similarly, "--gst-debug-level=<TAB>" won't complete properly (on bash 3), but "--gst-debug-level <TAB>" will. For that reason, I now offer "--gst-debug-level" etc as completions instead of "--gst-debug-level=". Functions "_init_completion" and "_parse_help" were provided by the bash-completion package >= 2.0; now I roll my own equivalent of "_parse_help", and instead of "_init_completion" I use "_get_comp_words_by_ref" which is available from bash-completion 1.2 onwards. If the bash-completion package isn't available at all I use bash's raw facilities, at the expense of not completing properly when the cursor is in the middle of a word. The builtin "compopt" doesn't exist in bash 3; those users will just have to live with the inconvenience of "property=" completing to "property= " with a trailing space. Property values aren't completed properly anyway on bash 3 (see above). "[[ -v var ]]" to test whether a variable is set, also doesn't exist in bash 3. Neither does ";;&" to fall through in a "case" statement. In the unit tests: * On my system (OS X), "#!/bin/bash" is bash 3.2, whereas "#!/usr/bin/env bash" is the 4.2 version I built myself. * I have to initialise array variables like "expected=()", or bash 3 treats "+=" as appending to an array already populated with one empty string.
2012-12-21 08:56:26 +00:00
local cur cword prev words
_gst_init_completion
[[ "$cur" == "=" ]] && cur=
[[ "$cur" =~ -.*=*$ ]] && prev="${cur%%=*}" cur="${cur#*=}"
tools/gstreamer-completion: Bash 3.2 compatibility fixes Compatible with bash 3.2; doesn't require the bash-completion package at all (though the easiest way to install this script is still to install bash-completion, and then drop this script into /etc/bash_completion.d). Note that bash 3 doesn't break COMP_WORDS according to characters in COMP_WORDBREAKS, so "property=val" looks like a single word, so this won't complete property values (on bash 3). Similarly, "--gst-debug-level=<TAB>" won't complete properly (on bash 3), but "--gst-debug-level <TAB>" will. For that reason, I now offer "--gst-debug-level" etc as completions instead of "--gst-debug-level=". Functions "_init_completion" and "_parse_help" were provided by the bash-completion package >= 2.0; now I roll my own equivalent of "_parse_help", and instead of "_init_completion" I use "_get_comp_words_by_ref" which is available from bash-completion 1.2 onwards. If the bash-completion package isn't available at all I use bash's raw facilities, at the expense of not completing properly when the cursor is in the middle of a word. The builtin "compopt" doesn't exist in bash 3; those users will just have to live with the inconvenience of "property=" completing to "property= " with a trailing space. Property values aren't completed properly anyway on bash 3 (see above). "[[ -v var ]]" to test whether a variable is set, also doesn't exist in bash 3. Neither does ";;&" to fall through in a "case" statement. In the unit tests: * On my system (OS X), "#!/bin/bash" is bash 3.2, whereas "#!/usr/bin/env bash" is the 4.2 version I built myself. * I have to initialise array variables like "expected=()", or bash 3 treats "+=" as appending to an array already populated with one empty string.
2012-12-21 08:56:26 +00:00
tools/gstreamer-completion: Support gst-inspect, and gst-launch element properties Completes options like "--gst-debug-level" and the values of some of those options; completes gst-launch pipeline element names, property names, and even property values (for enum or boolean properties only). Doesn't complete all caps specifications, nor element names specified earlier in the pipeline with "name=...". The GStreamer version number is hard-coded into the completion script: This patch is off the master branch and has the version hard-coded as "1.0"; it needs to be updated if backported to the 0.10 branch. You could always create a "gstreamer-completion.in" that has the appropriate version inserted by "configure", but I'd rather not do that. The hard-coded version is consistent with the previous implementation of gstreamer-completion, which had the registry path hard-coded as ~/.gstreamer-1.0/registry.xml. Note that GStreamer 0.10 installs "gst-inspect" and "gst-inspect-0.10". "gst-inspect --help" only prints 4 flags (--help, --print, --gst-mm, gst-list-mm) whereas "gst-inspect-0.10 --help-all" prints the full list of flags. The same applies to "gst-launch" and "gst-launch-0.10". GStreamer 1.0 only installs "gst-inspect-1.0", not "gst-inspect". Requires bash 4; only tested with bash 4.2. Requires "bash-completion" (which you install with your system's package manager). Put this in /etc/bash_completion.d/ or in `pkg-config --variable=compatdir bash-completion`, where it will be loaded at the beginning of every new terminal session; or in `pgk-config --variable=completionsdir bash-completion`, renamed to match the name of the command it completes (e.g. "gst-launch-1.0", with an additional symlink named "gst-inspect-1.0"), where it will be autoloaded when needed. test-gstreamer-completion.sh is (for now) in tests/misc -- it might be worth creating "tests/check/tools", with all the necessary automake boilerplate, and moving test-gstreamer-completion.sh there, and have it run automatically with "make check". IF YOU'RE NEW TO BASH COMPLETION SCRIPTS ---------------------------------------- "complete -F _gst_launch gst-launch-1.0" means that bash will run the function "_gst_launch" to generate possible completions for the command "gst-launch-1.0". "_gst_launch" must return the possible completions in the array variable COMPREPLY. (Note on bash syntax: "V=(a b c)" assigns three elements to the array "V"). "compgen" prints a list of possible completions to standard output. Try it: compgen -W "abc1 abc2 def" -- "a" compgen -f -- "/" The last argument is the word currently being completed; compgen uses it to filter out the non-matching completions. We put "--" first, in case the word currently being completed starts with "-" or "--", so that it isn't treated as a flag to compgen. For the documentation of COMP_WORDS, COMP_CWORD, etc see http://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-COMP_005fCWORD-180 See also: * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html The bash-completion package provides the helper function "_init_completion" which populates variables "cur", "prev", and "words". See http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=blob;f=bash_completion;h=870811b4;hb=HEAD#l634 Note that by default, bash appends a space to the completed word. When the completion is "property=" we don't want a trailing space; calling "compopt -o nospace" modifies the currently-executing completion accordingly. See http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#index-compopt
2012-12-19 10:46:50 +00:00
_gst_common_options || return
COMPREPLY=( $(compgen \
tools/gstreamer-completion: Bash 3.2 compatibility fixes Compatible with bash 3.2; doesn't require the bash-completion package at all (though the easiest way to install this script is still to install bash-completion, and then drop this script into /etc/bash_completion.d). Note that bash 3 doesn't break COMP_WORDS according to characters in COMP_WORDBREAKS, so "property=val" looks like a single word, so this won't complete property values (on bash 3). Similarly, "--gst-debug-level=<TAB>" won't complete properly (on bash 3), but "--gst-debug-level <TAB>" will. For that reason, I now offer "--gst-debug-level" etc as completions instead of "--gst-debug-level=". Functions "_init_completion" and "_parse_help" were provided by the bash-completion package >= 2.0; now I roll my own equivalent of "_parse_help", and instead of "_init_completion" I use "_get_comp_words_by_ref" which is available from bash-completion 1.2 onwards. If the bash-completion package isn't available at all I use bash's raw facilities, at the expense of not completing properly when the cursor is in the middle of a word. The builtin "compopt" doesn't exist in bash 3; those users will just have to live with the inconvenience of "property=" completing to "property= " with a trailing space. Property values aren't completed properly anyway on bash 3 (see above). "[[ -v var ]]" to test whether a variable is set, also doesn't exist in bash 3. Neither does ";;&" to fall through in a "case" statement. In the unit tests: * On my system (OS X), "#!/bin/bash" is bash 3.2, whereas "#!/usr/bin/env bash" is the 4.2 version I built myself. * I have to initialise array variables like "expected=()", or bash 3 treats "+=" as appending to an array already populated with one empty string.
2012-12-21 08:56:26 +00:00
-W "$(_gst_parse_help gst-inspect-$_gst_version) \
tools/gstreamer-completion: Support gst-inspect, and gst-launch element properties Completes options like "--gst-debug-level" and the values of some of those options; completes gst-launch pipeline element names, property names, and even property values (for enum or boolean properties only). Doesn't complete all caps specifications, nor element names specified earlier in the pipeline with "name=...". The GStreamer version number is hard-coded into the completion script: This patch is off the master branch and has the version hard-coded as "1.0"; it needs to be updated if backported to the 0.10 branch. You could always create a "gstreamer-completion.in" that has the appropriate version inserted by "configure", but I'd rather not do that. The hard-coded version is consistent with the previous implementation of gstreamer-completion, which had the registry path hard-coded as ~/.gstreamer-1.0/registry.xml. Note that GStreamer 0.10 installs "gst-inspect" and "gst-inspect-0.10". "gst-inspect --help" only prints 4 flags (--help, --print, --gst-mm, gst-list-mm) whereas "gst-inspect-0.10 --help-all" prints the full list of flags. The same applies to "gst-launch" and "gst-launch-0.10". GStreamer 1.0 only installs "gst-inspect-1.0", not "gst-inspect". Requires bash 4; only tested with bash 4.2. Requires "bash-completion" (which you install with your system's package manager). Put this in /etc/bash_completion.d/ or in `pkg-config --variable=compatdir bash-completion`, where it will be loaded at the beginning of every new terminal session; or in `pgk-config --variable=completionsdir bash-completion`, renamed to match the name of the command it completes (e.g. "gst-launch-1.0", with an additional symlink named "gst-inspect-1.0"), where it will be autoloaded when needed. test-gstreamer-completion.sh is (for now) in tests/misc -- it might be worth creating "tests/check/tools", with all the necessary automake boilerplate, and moving test-gstreamer-completion.sh there, and have it run automatically with "make check". IF YOU'RE NEW TO BASH COMPLETION SCRIPTS ---------------------------------------- "complete -F _gst_launch gst-launch-1.0" means that bash will run the function "_gst_launch" to generate possible completions for the command "gst-launch-1.0". "_gst_launch" must return the possible completions in the array variable COMPREPLY. (Note on bash syntax: "V=(a b c)" assigns three elements to the array "V"). "compgen" prints a list of possible completions to standard output. Try it: compgen -W "abc1 abc2 def" -- "a" compgen -f -- "/" The last argument is the word currently being completed; compgen uses it to filter out the non-matching completions. We put "--" first, in case the word currently being completed starts with "-" or "--", so that it isn't treated as a flag to compgen. For the documentation of COMP_WORDS, COMP_CWORD, etc see http://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-COMP_005fCWORD-180 See also: * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html The bash-completion package provides the helper function "_init_completion" which populates variables "cur", "prev", and "words". See http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=blob;f=bash_completion;h=870811b4;hb=HEAD#l634 Note that by default, bash appends a space to the completed word. When the completion is "property=" we don't want a trailing space; calling "compopt -o nospace" modifies the currently-executing completion accordingly. See http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#index-compopt
2012-12-19 10:46:50 +00:00
$(_gst_plugins) $(_gst_elements)" \
-- "$cur") )
[[ $COMPREPLY == *= ]] && compopt -o nospace 2>/dev/null
} &&
complete -F _gst_inspect gst-inspect-1.0
_gst_launch() {
local _gst_version=1.0
tools/gstreamer-completion: Support gst-inspect, and gst-launch element properties Completes options like "--gst-debug-level" and the values of some of those options; completes gst-launch pipeline element names, property names, and even property values (for enum or boolean properties only). Doesn't complete all caps specifications, nor element names specified earlier in the pipeline with "name=...". The GStreamer version number is hard-coded into the completion script: This patch is off the master branch and has the version hard-coded as "1.0"; it needs to be updated if backported to the 0.10 branch. You could always create a "gstreamer-completion.in" that has the appropriate version inserted by "configure", but I'd rather not do that. The hard-coded version is consistent with the previous implementation of gstreamer-completion, which had the registry path hard-coded as ~/.gstreamer-1.0/registry.xml. Note that GStreamer 0.10 installs "gst-inspect" and "gst-inspect-0.10". "gst-inspect --help" only prints 4 flags (--help, --print, --gst-mm, gst-list-mm) whereas "gst-inspect-0.10 --help-all" prints the full list of flags. The same applies to "gst-launch" and "gst-launch-0.10". GStreamer 1.0 only installs "gst-inspect-1.0", not "gst-inspect". Requires bash 4; only tested with bash 4.2. Requires "bash-completion" (which you install with your system's package manager). Put this in /etc/bash_completion.d/ or in `pkg-config --variable=compatdir bash-completion`, where it will be loaded at the beginning of every new terminal session; or in `pgk-config --variable=completionsdir bash-completion`, renamed to match the name of the command it completes (e.g. "gst-launch-1.0", with an additional symlink named "gst-inspect-1.0"), where it will be autoloaded when needed. test-gstreamer-completion.sh is (for now) in tests/misc -- it might be worth creating "tests/check/tools", with all the necessary automake boilerplate, and moving test-gstreamer-completion.sh there, and have it run automatically with "make check". IF YOU'RE NEW TO BASH COMPLETION SCRIPTS ---------------------------------------- "complete -F _gst_launch gst-launch-1.0" means that bash will run the function "_gst_launch" to generate possible completions for the command "gst-launch-1.0". "_gst_launch" must return the possible completions in the array variable COMPREPLY. (Note on bash syntax: "V=(a b c)" assigns three elements to the array "V"). "compgen" prints a list of possible completions to standard output. Try it: compgen -W "abc1 abc2 def" -- "a" compgen -f -- "/" The last argument is the word currently being completed; compgen uses it to filter out the non-matching completions. We put "--" first, in case the word currently being completed starts with "-" or "--", so that it isn't treated as a flag to compgen. For the documentation of COMP_WORDS, COMP_CWORD, etc see http://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-COMP_005fCWORD-180 See also: * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html The bash-completion package provides the helper function "_init_completion" which populates variables "cur", "prev", and "words". See http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=blob;f=bash_completion;h=870811b4;hb=HEAD#l634 Note that by default, bash appends a space to the completed word. When the completion is "property=" we don't want a trailing space; calling "compopt -o nospace" modifies the currently-executing completion accordingly. See http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#index-compopt
2012-12-19 10:46:50 +00:00
local cur cword prev words
tools/gstreamer-completion: Bash 3.2 compatibility fixes Compatible with bash 3.2; doesn't require the bash-completion package at all (though the easiest way to install this script is still to install bash-completion, and then drop this script into /etc/bash_completion.d). Note that bash 3 doesn't break COMP_WORDS according to characters in COMP_WORDBREAKS, so "property=val" looks like a single word, so this won't complete property values (on bash 3). Similarly, "--gst-debug-level=<TAB>" won't complete properly (on bash 3), but "--gst-debug-level <TAB>" will. For that reason, I now offer "--gst-debug-level" etc as completions instead of "--gst-debug-level=". Functions "_init_completion" and "_parse_help" were provided by the bash-completion package >= 2.0; now I roll my own equivalent of "_parse_help", and instead of "_init_completion" I use "_get_comp_words_by_ref" which is available from bash-completion 1.2 onwards. If the bash-completion package isn't available at all I use bash's raw facilities, at the expense of not completing properly when the cursor is in the middle of a word. The builtin "compopt" doesn't exist in bash 3; those users will just have to live with the inconvenience of "property=" completing to "property= " with a trailing space. Property values aren't completed properly anyway on bash 3 (see above). "[[ -v var ]]" to test whether a variable is set, also doesn't exist in bash 3. Neither does ";;&" to fall through in a "case" statement. In the unit tests: * On my system (OS X), "#!/bin/bash" is bash 3.2, whereas "#!/usr/bin/env bash" is the 4.2 version I built myself. * I have to initialise array variables like "expected=()", or bash 3 treats "+=" as appending to an array already populated with one empty string.
2012-12-21 08:56:26 +00:00
_gst_init_completion
tools/gstreamer-completion: Support gst-inspect, and gst-launch element properties Completes options like "--gst-debug-level" and the values of some of those options; completes gst-launch pipeline element names, property names, and even property values (for enum or boolean properties only). Doesn't complete all caps specifications, nor element names specified earlier in the pipeline with "name=...". The GStreamer version number is hard-coded into the completion script: This patch is off the master branch and has the version hard-coded as "1.0"; it needs to be updated if backported to the 0.10 branch. You could always create a "gstreamer-completion.in" that has the appropriate version inserted by "configure", but I'd rather not do that. The hard-coded version is consistent with the previous implementation of gstreamer-completion, which had the registry path hard-coded as ~/.gstreamer-1.0/registry.xml. Note that GStreamer 0.10 installs "gst-inspect" and "gst-inspect-0.10". "gst-inspect --help" only prints 4 flags (--help, --print, --gst-mm, gst-list-mm) whereas "gst-inspect-0.10 --help-all" prints the full list of flags. The same applies to "gst-launch" and "gst-launch-0.10". GStreamer 1.0 only installs "gst-inspect-1.0", not "gst-inspect". Requires bash 4; only tested with bash 4.2. Requires "bash-completion" (which you install with your system's package manager). Put this in /etc/bash_completion.d/ or in `pkg-config --variable=compatdir bash-completion`, where it will be loaded at the beginning of every new terminal session; or in `pgk-config --variable=completionsdir bash-completion`, renamed to match the name of the command it completes (e.g. "gst-launch-1.0", with an additional symlink named "gst-inspect-1.0"), where it will be autoloaded when needed. test-gstreamer-completion.sh is (for now) in tests/misc -- it might be worth creating "tests/check/tools", with all the necessary automake boilerplate, and moving test-gstreamer-completion.sh there, and have it run automatically with "make check". IF YOU'RE NEW TO BASH COMPLETION SCRIPTS ---------------------------------------- "complete -F _gst_launch gst-launch-1.0" means that bash will run the function "_gst_launch" to generate possible completions for the command "gst-launch-1.0". "_gst_launch" must return the possible completions in the array variable COMPREPLY. (Note on bash syntax: "V=(a b c)" assigns three elements to the array "V"). "compgen" prints a list of possible completions to standard output. Try it: compgen -W "abc1 abc2 def" -- "a" compgen -f -- "/" The last argument is the word currently being completed; compgen uses it to filter out the non-matching completions. We put "--" first, in case the word currently being completed starts with "-" or "--", so that it isn't treated as a flag to compgen. For the documentation of COMP_WORDS, COMP_CWORD, etc see http://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-COMP_005fCWORD-180 See also: * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html The bash-completion package provides the helper function "_init_completion" which populates variables "cur", "prev", and "words". See http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=blob;f=bash_completion;h=870811b4;hb=HEAD#l634 Note that by default, bash appends a space to the completed word. When the completion is "property=" we don't want a trailing space; calling "compopt -o nospace" modifies the currently-executing completion accordingly. See http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#index-compopt
2012-12-19 10:46:50 +00:00
local curtype option element property
_gst_launch_parse
_gst_common_options || return
COMPREPLY=( $(_gst_launch_compgen) )
[[ $COMPREPLY == *= ]] && compopt -o nospace 2>/dev/null
} &&
complete -o default -F _gst_launch gst-launch-1.0
tools/gstreamer-completion: Support gst-inspect, and gst-launch element properties Completes options like "--gst-debug-level" and the values of some of those options; completes gst-launch pipeline element names, property names, and even property values (for enum or boolean properties only). Doesn't complete all caps specifications, nor element names specified earlier in the pipeline with "name=...". The GStreamer version number is hard-coded into the completion script: This patch is off the master branch and has the version hard-coded as "1.0"; it needs to be updated if backported to the 0.10 branch. You could always create a "gstreamer-completion.in" that has the appropriate version inserted by "configure", but I'd rather not do that. The hard-coded version is consistent with the previous implementation of gstreamer-completion, which had the registry path hard-coded as ~/.gstreamer-1.0/registry.xml. Note that GStreamer 0.10 installs "gst-inspect" and "gst-inspect-0.10". "gst-inspect --help" only prints 4 flags (--help, --print, --gst-mm, gst-list-mm) whereas "gst-inspect-0.10 --help-all" prints the full list of flags. The same applies to "gst-launch" and "gst-launch-0.10". GStreamer 1.0 only installs "gst-inspect-1.0", not "gst-inspect". Requires bash 4; only tested with bash 4.2. Requires "bash-completion" (which you install with your system's package manager). Put this in /etc/bash_completion.d/ or in `pkg-config --variable=compatdir bash-completion`, where it will be loaded at the beginning of every new terminal session; or in `pgk-config --variable=completionsdir bash-completion`, renamed to match the name of the command it completes (e.g. "gst-launch-1.0", with an additional symlink named "gst-inspect-1.0"), where it will be autoloaded when needed. test-gstreamer-completion.sh is (for now) in tests/misc -- it might be worth creating "tests/check/tools", with all the necessary automake boilerplate, and moving test-gstreamer-completion.sh there, and have it run automatically with "make check". IF YOU'RE NEW TO BASH COMPLETION SCRIPTS ---------------------------------------- "complete -F _gst_launch gst-launch-1.0" means that bash will run the function "_gst_launch" to generate possible completions for the command "gst-launch-1.0". "_gst_launch" must return the possible completions in the array variable COMPREPLY. (Note on bash syntax: "V=(a b c)" assigns three elements to the array "V"). "compgen" prints a list of possible completions to standard output. Try it: compgen -W "abc1 abc2 def" -- "a" compgen -f -- "/" The last argument is the word currently being completed; compgen uses it to filter out the non-matching completions. We put "--" first, in case the word currently being completed starts with "-" or "--", so that it isn't treated as a flag to compgen. For the documentation of COMP_WORDS, COMP_CWORD, etc see http://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-COMP_005fCWORD-180 See also: * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html The bash-completion package provides the helper function "_init_completion" which populates variables "cur", "prev", and "words". See http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=blob;f=bash_completion;h=870811b4;hb=HEAD#l634 Note that by default, bash appends a space to the completed word. When the completion is "property=" we don't want a trailing space; calling "compopt -o nospace" modifies the currently-executing completion accordingly. See http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#index-compopt
2012-12-19 10:46:50 +00:00
_gst_common_options() {
tools/gstreamer-completion: Bash 3.2 compatibility fixes Compatible with bash 3.2; doesn't require the bash-completion package at all (though the easiest way to install this script is still to install bash-completion, and then drop this script into /etc/bash_completion.d). Note that bash 3 doesn't break COMP_WORDS according to characters in COMP_WORDBREAKS, so "property=val" looks like a single word, so this won't complete property values (on bash 3). Similarly, "--gst-debug-level=<TAB>" won't complete properly (on bash 3), but "--gst-debug-level <TAB>" will. For that reason, I now offer "--gst-debug-level" etc as completions instead of "--gst-debug-level=". Functions "_init_completion" and "_parse_help" were provided by the bash-completion package >= 2.0; now I roll my own equivalent of "_parse_help", and instead of "_init_completion" I use "_get_comp_words_by_ref" which is available from bash-completion 1.2 onwards. If the bash-completion package isn't available at all I use bash's raw facilities, at the expense of not completing properly when the cursor is in the middle of a word. The builtin "compopt" doesn't exist in bash 3; those users will just have to live with the inconvenience of "property=" completing to "property= " with a trailing space. Property values aren't completed properly anyway on bash 3 (see above). "[[ -v var ]]" to test whether a variable is set, also doesn't exist in bash 3. Neither does ";;&" to fall through in a "case" statement. In the unit tests: * On my system (OS X), "#!/bin/bash" is bash 3.2, whereas "#!/usr/bin/env bash" is the 4.2 version I built myself. * I have to initialise array variables like "expected=()", or bash 3 treats "+=" as appending to an array already populated with one empty string.
2012-12-21 08:56:26 +00:00
if [[ -n "$curtype" ]]; then # Called from _gst_launch
tools/gstreamer-completion: Support gst-inspect, and gst-launch element properties Completes options like "--gst-debug-level" and the values of some of those options; completes gst-launch pipeline element names, property names, and even property values (for enum or boolean properties only). Doesn't complete all caps specifications, nor element names specified earlier in the pipeline with "name=...". The GStreamer version number is hard-coded into the completion script: This patch is off the master branch and has the version hard-coded as "1.0"; it needs to be updated if backported to the 0.10 branch. You could always create a "gstreamer-completion.in" that has the appropriate version inserted by "configure", but I'd rather not do that. The hard-coded version is consistent with the previous implementation of gstreamer-completion, which had the registry path hard-coded as ~/.gstreamer-1.0/registry.xml. Note that GStreamer 0.10 installs "gst-inspect" and "gst-inspect-0.10". "gst-inspect --help" only prints 4 flags (--help, --print, --gst-mm, gst-list-mm) whereas "gst-inspect-0.10 --help-all" prints the full list of flags. The same applies to "gst-launch" and "gst-launch-0.10". GStreamer 1.0 only installs "gst-inspect-1.0", not "gst-inspect". Requires bash 4; only tested with bash 4.2. Requires "bash-completion" (which you install with your system's package manager). Put this in /etc/bash_completion.d/ or in `pkg-config --variable=compatdir bash-completion`, where it will be loaded at the beginning of every new terminal session; or in `pgk-config --variable=completionsdir bash-completion`, renamed to match the name of the command it completes (e.g. "gst-launch-1.0", with an additional symlink named "gst-inspect-1.0"), where it will be autoloaded when needed. test-gstreamer-completion.sh is (for now) in tests/misc -- it might be worth creating "tests/check/tools", with all the necessary automake boilerplate, and moving test-gstreamer-completion.sh there, and have it run automatically with "make check". IF YOU'RE NEW TO BASH COMPLETION SCRIPTS ---------------------------------------- "complete -F _gst_launch gst-launch-1.0" means that bash will run the function "_gst_launch" to generate possible completions for the command "gst-launch-1.0". "_gst_launch" must return the possible completions in the array variable COMPREPLY. (Note on bash syntax: "V=(a b c)" assigns three elements to the array "V"). "compgen" prints a list of possible completions to standard output. Try it: compgen -W "abc1 abc2 def" -- "a" compgen -f -- "/" The last argument is the word currently being completed; compgen uses it to filter out the non-matching completions. We put "--" first, in case the word currently being completed starts with "-" or "--", so that it isn't treated as a flag to compgen. For the documentation of COMP_WORDS, COMP_CWORD, etc see http://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-COMP_005fCWORD-180 See also: * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html The bash-completion package provides the helper function "_init_completion" which populates variables "cur", "prev", and "words". See http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=blob;f=bash_completion;h=870811b4;hb=HEAD#l634 Note that by default, bash appends a space to the completed word. When the completion is "property=" we don't want a trailing space; calling "compopt -o nospace" modifies the currently-executing completion accordingly. See http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#index-compopt
2012-12-19 10:46:50 +00:00
[[ $curtype == optionval ]] || return 0
else # Called from _gst_inspect
local option="$prev"
fi
case "$option" in
--gst-debug-level)
COMPREPLY=( $(compgen -W "0 1 2 3 4 5" -- "$cur") );;
--gst-debug) # TODO: comma-separated list of category_name:level pairs.
;;
--gst-plugin-path) # TODO: support multiple (colon-separated) paths.
COMPREPLY=( $(compgen -d -- "$cur") );;
--gst-plugin-load) # TODO: comma-separated list of plugins (files?).
;;
*) return 0;;
esac
return 1 # No need to attempt further completions.
}
_gst_launch_compgen() {
case $curtype in
tools/gstreamer-completion: Bash 3.2 compatibility fixes Compatible with bash 3.2; doesn't require the bash-completion package at all (though the easiest way to install this script is still to install bash-completion, and then drop this script into /etc/bash_completion.d). Note that bash 3 doesn't break COMP_WORDS according to characters in COMP_WORDBREAKS, so "property=val" looks like a single word, so this won't complete property values (on bash 3). Similarly, "--gst-debug-level=<TAB>" won't complete properly (on bash 3), but "--gst-debug-level <TAB>" will. For that reason, I now offer "--gst-debug-level" etc as completions instead of "--gst-debug-level=". Functions "_init_completion" and "_parse_help" were provided by the bash-completion package >= 2.0; now I roll my own equivalent of "_parse_help", and instead of "_init_completion" I use "_get_comp_words_by_ref" which is available from bash-completion 1.2 onwards. If the bash-completion package isn't available at all I use bash's raw facilities, at the expense of not completing properly when the cursor is in the middle of a word. The builtin "compopt" doesn't exist in bash 3; those users will just have to live with the inconvenience of "property=" completing to "property= " with a trailing space. Property values aren't completed properly anyway on bash 3 (see above). "[[ -v var ]]" to test whether a variable is set, also doesn't exist in bash 3. Neither does ";;&" to fall through in a "case" statement. In the unit tests: * On my system (OS X), "#!/bin/bash" is bash 3.2, whereas "#!/usr/bin/env bash" is the 4.2 version I built myself. * I have to initialise array variables like "expected=()", or bash 3 treats "+=" as appending to an array already populated with one empty string.
2012-12-21 08:56:26 +00:00
option)
tools/gstreamer-completion: Support gst-inspect, and gst-launch element properties Completes options like "--gst-debug-level" and the values of some of those options; completes gst-launch pipeline element names, property names, and even property values (for enum or boolean properties only). Doesn't complete all caps specifications, nor element names specified earlier in the pipeline with "name=...". The GStreamer version number is hard-coded into the completion script: This patch is off the master branch and has the version hard-coded as "1.0"; it needs to be updated if backported to the 0.10 branch. You could always create a "gstreamer-completion.in" that has the appropriate version inserted by "configure", but I'd rather not do that. The hard-coded version is consistent with the previous implementation of gstreamer-completion, which had the registry path hard-coded as ~/.gstreamer-1.0/registry.xml. Note that GStreamer 0.10 installs "gst-inspect" and "gst-inspect-0.10". "gst-inspect --help" only prints 4 flags (--help, --print, --gst-mm, gst-list-mm) whereas "gst-inspect-0.10 --help-all" prints the full list of flags. The same applies to "gst-launch" and "gst-launch-0.10". GStreamer 1.0 only installs "gst-inspect-1.0", not "gst-inspect". Requires bash 4; only tested with bash 4.2. Requires "bash-completion" (which you install with your system's package manager). Put this in /etc/bash_completion.d/ or in `pkg-config --variable=compatdir bash-completion`, where it will be loaded at the beginning of every new terminal session; or in `pgk-config --variable=completionsdir bash-completion`, renamed to match the name of the command it completes (e.g. "gst-launch-1.0", with an additional symlink named "gst-inspect-1.0"), where it will be autoloaded when needed. test-gstreamer-completion.sh is (for now) in tests/misc -- it might be worth creating "tests/check/tools", with all the necessary automake boilerplate, and moving test-gstreamer-completion.sh there, and have it run automatically with "make check". IF YOU'RE NEW TO BASH COMPLETION SCRIPTS ---------------------------------------- "complete -F _gst_launch gst-launch-1.0" means that bash will run the function "_gst_launch" to generate possible completions for the command "gst-launch-1.0". "_gst_launch" must return the possible completions in the array variable COMPREPLY. (Note on bash syntax: "V=(a b c)" assigns three elements to the array "V"). "compgen" prints a list of possible completions to standard output. Try it: compgen -W "abc1 abc2 def" -- "a" compgen -f -- "/" The last argument is the word currently being completed; compgen uses it to filter out the non-matching completions. We put "--" first, in case the word currently being completed starts with "-" or "--", so that it isn't treated as a flag to compgen. For the documentation of COMP_WORDS, COMP_CWORD, etc see http://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-COMP_005fCWORD-180 See also: * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html The bash-completion package provides the helper function "_init_completion" which populates variables "cur", "prev", and "words". See http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=blob;f=bash_completion;h=870811b4;hb=HEAD#l634 Note that by default, bash appends a space to the completed word. When the completion is "property=" we don't want a trailing space; calling "compopt -o nospace" modifies the currently-executing completion accordingly. See http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#index-compopt
2012-12-19 10:46:50 +00:00
compgen \
tools/gstreamer-completion: Bash 3.2 compatibility fixes Compatible with bash 3.2; doesn't require the bash-completion package at all (though the easiest way to install this script is still to install bash-completion, and then drop this script into /etc/bash_completion.d). Note that bash 3 doesn't break COMP_WORDS according to characters in COMP_WORDBREAKS, so "property=val" looks like a single word, so this won't complete property values (on bash 3). Similarly, "--gst-debug-level=<TAB>" won't complete properly (on bash 3), but "--gst-debug-level <TAB>" will. For that reason, I now offer "--gst-debug-level" etc as completions instead of "--gst-debug-level=". Functions "_init_completion" and "_parse_help" were provided by the bash-completion package >= 2.0; now I roll my own equivalent of "_parse_help", and instead of "_init_completion" I use "_get_comp_words_by_ref" which is available from bash-completion 1.2 onwards. If the bash-completion package isn't available at all I use bash's raw facilities, at the expense of not completing properly when the cursor is in the middle of a word. The builtin "compopt" doesn't exist in bash 3; those users will just have to live with the inconvenience of "property=" completing to "property= " with a trailing space. Property values aren't completed properly anyway on bash 3 (see above). "[[ -v var ]]" to test whether a variable is set, also doesn't exist in bash 3. Neither does ";;&" to fall through in a "case" statement. In the unit tests: * On my system (OS X), "#!/bin/bash" is bash 3.2, whereas "#!/usr/bin/env bash" is the 4.2 version I built myself. * I have to initialise array variables like "expected=()", or bash 3 treats "+=" as appending to an array already populated with one empty string.
2012-12-21 08:56:26 +00:00
-W "$(_gst_parse_help gst-launch-$_gst_version)" \
-- "$cur" ;;
element)
tools/gstreamer-completion: Support gst-inspect, and gst-launch element properties Completes options like "--gst-debug-level" and the values of some of those options; completes gst-launch pipeline element names, property names, and even property values (for enum or boolean properties only). Doesn't complete all caps specifications, nor element names specified earlier in the pipeline with "name=...". The GStreamer version number is hard-coded into the completion script: This patch is off the master branch and has the version hard-coded as "1.0"; it needs to be updated if backported to the 0.10 branch. You could always create a "gstreamer-completion.in" that has the appropriate version inserted by "configure", but I'd rather not do that. The hard-coded version is consistent with the previous implementation of gstreamer-completion, which had the registry path hard-coded as ~/.gstreamer-1.0/registry.xml. Note that GStreamer 0.10 installs "gst-inspect" and "gst-inspect-0.10". "gst-inspect --help" only prints 4 flags (--help, --print, --gst-mm, gst-list-mm) whereas "gst-inspect-0.10 --help-all" prints the full list of flags. The same applies to "gst-launch" and "gst-launch-0.10". GStreamer 1.0 only installs "gst-inspect-1.0", not "gst-inspect". Requires bash 4; only tested with bash 4.2. Requires "bash-completion" (which you install with your system's package manager). Put this in /etc/bash_completion.d/ or in `pkg-config --variable=compatdir bash-completion`, where it will be loaded at the beginning of every new terminal session; or in `pgk-config --variable=completionsdir bash-completion`, renamed to match the name of the command it completes (e.g. "gst-launch-1.0", with an additional symlink named "gst-inspect-1.0"), where it will be autoloaded when needed. test-gstreamer-completion.sh is (for now) in tests/misc -- it might be worth creating "tests/check/tools", with all the necessary automake boilerplate, and moving test-gstreamer-completion.sh there, and have it run automatically with "make check". IF YOU'RE NEW TO BASH COMPLETION SCRIPTS ---------------------------------------- "complete -F _gst_launch gst-launch-1.0" means that bash will run the function "_gst_launch" to generate possible completions for the command "gst-launch-1.0". "_gst_launch" must return the possible completions in the array variable COMPREPLY. (Note on bash syntax: "V=(a b c)" assigns three elements to the array "V"). "compgen" prints a list of possible completions to standard output. Try it: compgen -W "abc1 abc2 def" -- "a" compgen -f -- "/" The last argument is the word currently being completed; compgen uses it to filter out the non-matching completions. We put "--" first, in case the word currently being completed starts with "-" or "--", so that it isn't treated as a flag to compgen. For the documentation of COMP_WORDS, COMP_CWORD, etc see http://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-COMP_005fCWORD-180 See also: * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html The bash-completion package provides the helper function "_init_completion" which populates variables "cur", "prev", and "words". See http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=blob;f=bash_completion;h=870811b4;hb=HEAD#l634 Note that by default, bash appends a space to the completed word. When the completion is "property=" we don't want a trailing space; calling "compopt -o nospace" modifies the currently-executing completion accordingly. See http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#index-compopt
2012-12-19 10:46:50 +00:00
compgen -W "$(_gst_elements)" -- "$cur" ;;
tools/gstreamer-completion: Bash 3.2 compatibility fixes Compatible with bash 3.2; doesn't require the bash-completion package at all (though the easiest way to install this script is still to install bash-completion, and then drop this script into /etc/bash_completion.d). Note that bash 3 doesn't break COMP_WORDS according to characters in COMP_WORDBREAKS, so "property=val" looks like a single word, so this won't complete property values (on bash 3). Similarly, "--gst-debug-level=<TAB>" won't complete properly (on bash 3), but "--gst-debug-level <TAB>" will. For that reason, I now offer "--gst-debug-level" etc as completions instead of "--gst-debug-level=". Functions "_init_completion" and "_parse_help" were provided by the bash-completion package >= 2.0; now I roll my own equivalent of "_parse_help", and instead of "_init_completion" I use "_get_comp_words_by_ref" which is available from bash-completion 1.2 onwards. If the bash-completion package isn't available at all I use bash's raw facilities, at the expense of not completing properly when the cursor is in the middle of a word. The builtin "compopt" doesn't exist in bash 3; those users will just have to live with the inconvenience of "property=" completing to "property= " with a trailing space. Property values aren't completed properly anyway on bash 3 (see above). "[[ -v var ]]" to test whether a variable is set, also doesn't exist in bash 3. Neither does ";;&" to fall through in a "case" statement. In the unit tests: * On my system (OS X), "#!/bin/bash" is bash 3.2, whereas "#!/usr/bin/env bash" is the 4.2 version I built myself. * I have to initialise array variables like "expected=()", or bash 3 treats "+=" as appending to an array already populated with one empty string.
2012-12-21 08:56:26 +00:00
option-or-element)
compgen \
-W "$(_gst_parse_help gst-launch-$_gst_version) \
$(_gst_elements)" \
-- "$cur" ;;
tools/gstreamer-completion: Support gst-inspect, and gst-launch element properties Completes options like "--gst-debug-level" and the values of some of those options; completes gst-launch pipeline element names, property names, and even property values (for enum or boolean properties only). Doesn't complete all caps specifications, nor element names specified earlier in the pipeline with "name=...". The GStreamer version number is hard-coded into the completion script: This patch is off the master branch and has the version hard-coded as "1.0"; it needs to be updated if backported to the 0.10 branch. You could always create a "gstreamer-completion.in" that has the appropriate version inserted by "configure", but I'd rather not do that. The hard-coded version is consistent with the previous implementation of gstreamer-completion, which had the registry path hard-coded as ~/.gstreamer-1.0/registry.xml. Note that GStreamer 0.10 installs "gst-inspect" and "gst-inspect-0.10". "gst-inspect --help" only prints 4 flags (--help, --print, --gst-mm, gst-list-mm) whereas "gst-inspect-0.10 --help-all" prints the full list of flags. The same applies to "gst-launch" and "gst-launch-0.10". GStreamer 1.0 only installs "gst-inspect-1.0", not "gst-inspect". Requires bash 4; only tested with bash 4.2. Requires "bash-completion" (which you install with your system's package manager). Put this in /etc/bash_completion.d/ or in `pkg-config --variable=compatdir bash-completion`, where it will be loaded at the beginning of every new terminal session; or in `pgk-config --variable=completionsdir bash-completion`, renamed to match the name of the command it completes (e.g. "gst-launch-1.0", with an additional symlink named "gst-inspect-1.0"), where it will be autoloaded when needed. test-gstreamer-completion.sh is (for now) in tests/misc -- it might be worth creating "tests/check/tools", with all the necessary automake boilerplate, and moving test-gstreamer-completion.sh there, and have it run automatically with "make check". IF YOU'RE NEW TO BASH COMPLETION SCRIPTS ---------------------------------------- "complete -F _gst_launch gst-launch-1.0" means that bash will run the function "_gst_launch" to generate possible completions for the command "gst-launch-1.0". "_gst_launch" must return the possible completions in the array variable COMPREPLY. (Note on bash syntax: "V=(a b c)" assigns three elements to the array "V"). "compgen" prints a list of possible completions to standard output. Try it: compgen -W "abc1 abc2 def" -- "a" compgen -f -- "/" The last argument is the word currently being completed; compgen uses it to filter out the non-matching completions. We put "--" first, in case the word currently being completed starts with "-" or "--", so that it isn't treated as a flag to compgen. For the documentation of COMP_WORDS, COMP_CWORD, etc see http://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-COMP_005fCWORD-180 See also: * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html The bash-completion package provides the helper function "_init_completion" which populates variables "cur", "prev", and "words". See http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=blob;f=bash_completion;h=870811b4;hb=HEAD#l634 Note that by default, bash appends a space to the completed word. When the completion is "property=" we don't want a trailing space; calling "compopt -o nospace" modifies the currently-executing completion accordingly. See http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#index-compopt
2012-12-19 10:46:50 +00:00
optionval)
case "$option" in
-o|--output) compgen -f -- "$cur" ;;
--exclude) ;; # TODO: comma-separated list of status information types.
esac ;;
\!)
compgen -W '!' -- "$cur" ;;
property)
compgen -W "$(_gst_properties $element) ! " -- "$cur" ;;
propertyval)
compgen -W "$(_gst_property_values $element $property)" -- "$cur" ;;
esac
}
_gst_plugins() {
gst-inspect-$_gst_version 2>/dev/null |
grep -v 'Total count' |
awk -F': +' '{print $1}' |
uniq
}
_gst_elements() {
tools/gstreamer-completion: Support gst-inspect, and gst-launch element properties Completes options like "--gst-debug-level" and the values of some of those options; completes gst-launch pipeline element names, property names, and even property values (for enum or boolean properties only). Doesn't complete all caps specifications, nor element names specified earlier in the pipeline with "name=...". The GStreamer version number is hard-coded into the completion script: This patch is off the master branch and has the version hard-coded as "1.0"; it needs to be updated if backported to the 0.10 branch. You could always create a "gstreamer-completion.in" that has the appropriate version inserted by "configure", but I'd rather not do that. The hard-coded version is consistent with the previous implementation of gstreamer-completion, which had the registry path hard-coded as ~/.gstreamer-1.0/registry.xml. Note that GStreamer 0.10 installs "gst-inspect" and "gst-inspect-0.10". "gst-inspect --help" only prints 4 flags (--help, --print, --gst-mm, gst-list-mm) whereas "gst-inspect-0.10 --help-all" prints the full list of flags. The same applies to "gst-launch" and "gst-launch-0.10". GStreamer 1.0 only installs "gst-inspect-1.0", not "gst-inspect". Requires bash 4; only tested with bash 4.2. Requires "bash-completion" (which you install with your system's package manager). Put this in /etc/bash_completion.d/ or in `pkg-config --variable=compatdir bash-completion`, where it will be loaded at the beginning of every new terminal session; or in `pgk-config --variable=completionsdir bash-completion`, renamed to match the name of the command it completes (e.g. "gst-launch-1.0", with an additional symlink named "gst-inspect-1.0"), where it will be autoloaded when needed. test-gstreamer-completion.sh is (for now) in tests/misc -- it might be worth creating "tests/check/tools", with all the necessary automake boilerplate, and moving test-gstreamer-completion.sh there, and have it run automatically with "make check". IF YOU'RE NEW TO BASH COMPLETION SCRIPTS ---------------------------------------- "complete -F _gst_launch gst-launch-1.0" means that bash will run the function "_gst_launch" to generate possible completions for the command "gst-launch-1.0". "_gst_launch" must return the possible completions in the array variable COMPREPLY. (Note on bash syntax: "V=(a b c)" assigns three elements to the array "V"). "compgen" prints a list of possible completions to standard output. Try it: compgen -W "abc1 abc2 def" -- "a" compgen -f -- "/" The last argument is the word currently being completed; compgen uses it to filter out the non-matching completions. We put "--" first, in case the word currently being completed starts with "-" or "--", so that it isn't treated as a flag to compgen. For the documentation of COMP_WORDS, COMP_CWORD, etc see http://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-COMP_005fCWORD-180 See also: * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html The bash-completion package provides the helper function "_init_completion" which populates variables "cur", "prev", and "words". See http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=blob;f=bash_completion;h=870811b4;hb=HEAD#l634 Note that by default, bash appends a space to the completed word. When the completion is "property=" we don't want a trailing space; calling "compopt -o nospace" modifies the currently-executing completion accordingly. See http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#index-compopt
2012-12-19 10:46:50 +00:00
gst-inspect-$_gst_version 2>/dev/null |
grep -v 'Total count' |
awk -F': +' '{print $2}'
}
_gst_properties() {
local element="$1"
gst-inspect-$_gst_version "$element" 2>/dev/null |
sed -n '/^Element Properties:$/,$ p' |
awk '/^ [a-z]/ { print $1 "=" }'
}
_gst_property_values() {
local element=$1 property=$2
gst-inspect-$_gst_version $element 2>/dev/null |
awk "
/^Element Properties:\$/ { inproperties = 1; next; }
inproperties && /^ $property / { inproperty = 1; next; }
inproperty && /^ *Boolean/ { printf \"true\nfalse\n\"; exit; }
inproperty && /^ *Enum/ { inenum = 1; next; }
inenum && /^ *\([0-9]+\): / { print \$2; next; }
inproperty && /^ [a-z]/ { exit; }"
}
# Walks over $words, sets $curtype to the string:
#
# 'option' if $cur is an option or flag like "-a" or "--abc".
# 'optionval' if $cur is the value of an option
# (which will be set in $option).
# 'element' if $cur is a GStreamer element name.
# '!' if $cur is '!'.
# 'property' if $cur is the name of a property of a GStreamer element
# (which will be set in $element).
# 'propertyval' if $cur is the value of an element's property
# (which will be set in $element and $property, respectively).
#
# ($cur is the word currently being completed.)
#
# Before calling this function make sure that $curtype, $option, $element and
tools/gstreamer-completion: Bash 3.2 compatibility fixes Compatible with bash 3.2; doesn't require the bash-completion package at all (though the easiest way to install this script is still to install bash-completion, and then drop this script into /etc/bash_completion.d). Note that bash 3 doesn't break COMP_WORDS according to characters in COMP_WORDBREAKS, so "property=val" looks like a single word, so this won't complete property values (on bash 3). Similarly, "--gst-debug-level=<TAB>" won't complete properly (on bash 3), but "--gst-debug-level <TAB>" will. For that reason, I now offer "--gst-debug-level" etc as completions instead of "--gst-debug-level=". Functions "_init_completion" and "_parse_help" were provided by the bash-completion package >= 2.0; now I roll my own equivalent of "_parse_help", and instead of "_init_completion" I use "_get_comp_words_by_ref" which is available from bash-completion 1.2 onwards. If the bash-completion package isn't available at all I use bash's raw facilities, at the expense of not completing properly when the cursor is in the middle of a word. The builtin "compopt" doesn't exist in bash 3; those users will just have to live with the inconvenience of "property=" completing to "property= " with a trailing space. Property values aren't completed properly anyway on bash 3 (see above). "[[ -v var ]]" to test whether a variable is set, also doesn't exist in bash 3. Neither does ";;&" to fall through in a "case" statement. In the unit tests: * On my system (OS X), "#!/bin/bash" is bash 3.2, whereas "#!/usr/bin/env bash" is the 4.2 version I built myself. * I have to initialise array variables like "expected=()", or bash 3 treats "+=" as appending to an array already populated with one empty string.
2012-12-21 08:56:26 +00:00
# $property are local, and that $cur, $cword and $words have been initialised.
tools/gstreamer-completion: Support gst-inspect, and gst-launch element properties Completes options like "--gst-debug-level" and the values of some of those options; completes gst-launch pipeline element names, property names, and even property values (for enum or boolean properties only). Doesn't complete all caps specifications, nor element names specified earlier in the pipeline with "name=...". The GStreamer version number is hard-coded into the completion script: This patch is off the master branch and has the version hard-coded as "1.0"; it needs to be updated if backported to the 0.10 branch. You could always create a "gstreamer-completion.in" that has the appropriate version inserted by "configure", but I'd rather not do that. The hard-coded version is consistent with the previous implementation of gstreamer-completion, which had the registry path hard-coded as ~/.gstreamer-1.0/registry.xml. Note that GStreamer 0.10 installs "gst-inspect" and "gst-inspect-0.10". "gst-inspect --help" only prints 4 flags (--help, --print, --gst-mm, gst-list-mm) whereas "gst-inspect-0.10 --help-all" prints the full list of flags. The same applies to "gst-launch" and "gst-launch-0.10". GStreamer 1.0 only installs "gst-inspect-1.0", not "gst-inspect". Requires bash 4; only tested with bash 4.2. Requires "bash-completion" (which you install with your system's package manager). Put this in /etc/bash_completion.d/ or in `pkg-config --variable=compatdir bash-completion`, where it will be loaded at the beginning of every new terminal session; or in `pgk-config --variable=completionsdir bash-completion`, renamed to match the name of the command it completes (e.g. "gst-launch-1.0", with an additional symlink named "gst-inspect-1.0"), where it will be autoloaded when needed. test-gstreamer-completion.sh is (for now) in tests/misc -- it might be worth creating "tests/check/tools", with all the necessary automake boilerplate, and moving test-gstreamer-completion.sh there, and have it run automatically with "make check". IF YOU'RE NEW TO BASH COMPLETION SCRIPTS ---------------------------------------- "complete -F _gst_launch gst-launch-1.0" means that bash will run the function "_gst_launch" to generate possible completions for the command "gst-launch-1.0". "_gst_launch" must return the possible completions in the array variable COMPREPLY. (Note on bash syntax: "V=(a b c)" assigns three elements to the array "V"). "compgen" prints a list of possible completions to standard output. Try it: compgen -W "abc1 abc2 def" -- "a" compgen -f -- "/" The last argument is the word currently being completed; compgen uses it to filter out the non-matching completions. We put "--" first, in case the word currently being completed starts with "-" or "--", so that it isn't treated as a flag to compgen. For the documentation of COMP_WORDS, COMP_CWORD, etc see http://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-COMP_005fCWORD-180 See also: * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html The bash-completion package provides the helper function "_init_completion" which populates variables "cur", "prev", and "words". See http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=blob;f=bash_completion;h=870811b4;hb=HEAD#l634 Note that by default, bash appends a space to the completed word. When the completion is "property=" we don't want a trailing space; calling "compopt -o nospace" modifies the currently-executing completion accordingly. See http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#index-compopt
2012-12-19 10:46:50 +00:00
#
# See test cases in tests/misc/test-gstreamer-completion.sh in the
# gstreamer source repository.
#
_gst_launch_parse() {
local i next state
curtype= i=1 state=start
while [[ $i -le $cword ]]; do
next="${words[i]}"
# Note that COMP_WORDBREAKS by default includes "=" and ":".
case "$state,$next" in
start,-*=*) curtype=optionval option="${next%%=*}" state=start;;
tools/gstreamer-completion: Support gst-inspect, and gst-launch element properties Completes options like "--gst-debug-level" and the values of some of those options; completes gst-launch pipeline element names, property names, and even property values (for enum or boolean properties only). Doesn't complete all caps specifications, nor element names specified earlier in the pipeline with "name=...". The GStreamer version number is hard-coded into the completion script: This patch is off the master branch and has the version hard-coded as "1.0"; it needs to be updated if backported to the 0.10 branch. You could always create a "gstreamer-completion.in" that has the appropriate version inserted by "configure", but I'd rather not do that. The hard-coded version is consistent with the previous implementation of gstreamer-completion, which had the registry path hard-coded as ~/.gstreamer-1.0/registry.xml. Note that GStreamer 0.10 installs "gst-inspect" and "gst-inspect-0.10". "gst-inspect --help" only prints 4 flags (--help, --print, --gst-mm, gst-list-mm) whereas "gst-inspect-0.10 --help-all" prints the full list of flags. The same applies to "gst-launch" and "gst-launch-0.10". GStreamer 1.0 only installs "gst-inspect-1.0", not "gst-inspect". Requires bash 4; only tested with bash 4.2. Requires "bash-completion" (which you install with your system's package manager). Put this in /etc/bash_completion.d/ or in `pkg-config --variable=compatdir bash-completion`, where it will be loaded at the beginning of every new terminal session; or in `pgk-config --variable=completionsdir bash-completion`, renamed to match the name of the command it completes (e.g. "gst-launch-1.0", with an additional symlink named "gst-inspect-1.0"), where it will be autoloaded when needed. test-gstreamer-completion.sh is (for now) in tests/misc -- it might be worth creating "tests/check/tools", with all the necessary automake boilerplate, and moving test-gstreamer-completion.sh there, and have it run automatically with "make check". IF YOU'RE NEW TO BASH COMPLETION SCRIPTS ---------------------------------------- "complete -F _gst_launch gst-launch-1.0" means that bash will run the function "_gst_launch" to generate possible completions for the command "gst-launch-1.0". "_gst_launch" must return the possible completions in the array variable COMPREPLY. (Note on bash syntax: "V=(a b c)" assigns three elements to the array "V"). "compgen" prints a list of possible completions to standard output. Try it: compgen -W "abc1 abc2 def" -- "a" compgen -f -- "/" The last argument is the word currently being completed; compgen uses it to filter out the non-matching completions. We put "--" first, in case the word currently being completed starts with "-" or "--", so that it isn't treated as a flag to compgen. For the documentation of COMP_WORDS, COMP_CWORD, etc see http://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-COMP_005fCWORD-180 See also: * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html The bash-completion package provides the helper function "_init_completion" which populates variables "cur", "prev", and "words". See http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=blob;f=bash_completion;h=870811b4;hb=HEAD#l634 Note that by default, bash appends a space to the completed word. When the completion is "property=" we don't want a trailing space; calling "compopt -o nospace" modifies the currently-executing completion accordingly. See http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#index-compopt
2012-12-19 10:46:50 +00:00
start,-*) curtype=option option="$next" state=option;;
start,) curtype=option-or-element;;
start,*) curtype=element element="$next" state=element;;
option,=) curtype=optionval state=option=;;
option,*) _gst_takes_arg "$option" &&
curtype=optionval state=start ||
# re-evaluate without incrementing i:
{ curtype= state=start; continue; }
;;
option=,*) curtype=optionval state=start;;
element,\!) curtype='!' state='!';;
\!,*) curtype=element element="$next" state=element;;
element,*=)
curtype=propertyval property="${next%=}" state=property=;;
element,*=*)
curtype=propertyval property="${next%%=*}" state=element;;
tools/gstreamer-completion: Support gst-inspect, and gst-launch element properties Completes options like "--gst-debug-level" and the values of some of those options; completes gst-launch pipeline element names, property names, and even property values (for enum or boolean properties only). Doesn't complete all caps specifications, nor element names specified earlier in the pipeline with "name=...". The GStreamer version number is hard-coded into the completion script: This patch is off the master branch and has the version hard-coded as "1.0"; it needs to be updated if backported to the 0.10 branch. You could always create a "gstreamer-completion.in" that has the appropriate version inserted by "configure", but I'd rather not do that. The hard-coded version is consistent with the previous implementation of gstreamer-completion, which had the registry path hard-coded as ~/.gstreamer-1.0/registry.xml. Note that GStreamer 0.10 installs "gst-inspect" and "gst-inspect-0.10". "gst-inspect --help" only prints 4 flags (--help, --print, --gst-mm, gst-list-mm) whereas "gst-inspect-0.10 --help-all" prints the full list of flags. The same applies to "gst-launch" and "gst-launch-0.10". GStreamer 1.0 only installs "gst-inspect-1.0", not "gst-inspect". Requires bash 4; only tested with bash 4.2. Requires "bash-completion" (which you install with your system's package manager). Put this in /etc/bash_completion.d/ or in `pkg-config --variable=compatdir bash-completion`, where it will be loaded at the beginning of every new terminal session; or in `pgk-config --variable=completionsdir bash-completion`, renamed to match the name of the command it completes (e.g. "gst-launch-1.0", with an additional symlink named "gst-inspect-1.0"), where it will be autoloaded when needed. test-gstreamer-completion.sh is (for now) in tests/misc -- it might be worth creating "tests/check/tools", with all the necessary automake boilerplate, and moving test-gstreamer-completion.sh there, and have it run automatically with "make check". IF YOU'RE NEW TO BASH COMPLETION SCRIPTS ---------------------------------------- "complete -F _gst_launch gst-launch-1.0" means that bash will run the function "_gst_launch" to generate possible completions for the command "gst-launch-1.0". "_gst_launch" must return the possible completions in the array variable COMPREPLY. (Note on bash syntax: "V=(a b c)" assigns three elements to the array "V"). "compgen" prints a list of possible completions to standard output. Try it: compgen -W "abc1 abc2 def" -- "a" compgen -f -- "/" The last argument is the word currently being completed; compgen uses it to filter out the non-matching completions. We put "--" first, in case the word currently being completed starts with "-" or "--", so that it isn't treated as a flag to compgen. For the documentation of COMP_WORDS, COMP_CWORD, etc see http://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-COMP_005fCWORD-180 See also: * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html The bash-completion package provides the helper function "_init_completion" which populates variables "cur", "prev", and "words". See http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=blob;f=bash_completion;h=870811b4;hb=HEAD#l634 Note that by default, bash appends a space to the completed word. When the completion is "property=" we don't want a trailing space; calling "compopt -o nospace" modifies the currently-executing completion accordingly. See http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#index-compopt
2012-12-19 10:46:50 +00:00
element,*) curtype=property property="$next" state=property;;
property,=) curtype=propertyval state=property=;;
property=,*) curtype=propertyval state=element;;
esac
i=$((i + 1))
done
cur="${cur#*=}"
tools/gstreamer-completion: Support gst-inspect, and gst-launch element properties Completes options like "--gst-debug-level" and the values of some of those options; completes gst-launch pipeline element names, property names, and even property values (for enum or boolean properties only). Doesn't complete all caps specifications, nor element names specified earlier in the pipeline with "name=...". The GStreamer version number is hard-coded into the completion script: This patch is off the master branch and has the version hard-coded as "1.0"; it needs to be updated if backported to the 0.10 branch. You could always create a "gstreamer-completion.in" that has the appropriate version inserted by "configure", but I'd rather not do that. The hard-coded version is consistent with the previous implementation of gstreamer-completion, which had the registry path hard-coded as ~/.gstreamer-1.0/registry.xml. Note that GStreamer 0.10 installs "gst-inspect" and "gst-inspect-0.10". "gst-inspect --help" only prints 4 flags (--help, --print, --gst-mm, gst-list-mm) whereas "gst-inspect-0.10 --help-all" prints the full list of flags. The same applies to "gst-launch" and "gst-launch-0.10". GStreamer 1.0 only installs "gst-inspect-1.0", not "gst-inspect". Requires bash 4; only tested with bash 4.2. Requires "bash-completion" (which you install with your system's package manager). Put this in /etc/bash_completion.d/ or in `pkg-config --variable=compatdir bash-completion`, where it will be loaded at the beginning of every new terminal session; or in `pgk-config --variable=completionsdir bash-completion`, renamed to match the name of the command it completes (e.g. "gst-launch-1.0", with an additional symlink named "gst-inspect-1.0"), where it will be autoloaded when needed. test-gstreamer-completion.sh is (for now) in tests/misc -- it might be worth creating "tests/check/tools", with all the necessary automake boilerplate, and moving test-gstreamer-completion.sh there, and have it run automatically with "make check". IF YOU'RE NEW TO BASH COMPLETION SCRIPTS ---------------------------------------- "complete -F _gst_launch gst-launch-1.0" means that bash will run the function "_gst_launch" to generate possible completions for the command "gst-launch-1.0". "_gst_launch" must return the possible completions in the array variable COMPREPLY. (Note on bash syntax: "V=(a b c)" assigns three elements to the array "V"). "compgen" prints a list of possible completions to standard output. Try it: compgen -W "abc1 abc2 def" -- "a" compgen -f -- "/" The last argument is the word currently being completed; compgen uses it to filter out the non-matching completions. We put "--" first, in case the word currently being completed starts with "-" or "--", so that it isn't treated as a flag to compgen. For the documentation of COMP_WORDS, COMP_CWORD, etc see http://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-COMP_005fCWORD-180 See also: * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html * http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html The bash-completion package provides the helper function "_init_completion" which populates variables "cur", "prev", and "words". See http://anonscm.debian.org/gitweb/?p=bash-completion/bash-completion.git;a=blob;f=bash_completion;h=870811b4;hb=HEAD#l634 Note that by default, bash appends a space to the completed word. When the completion is "property=" we don't want a trailing space; calling "compopt -o nospace" modifies the currently-executing completion accordingly. See http://www.gnu.org/software/bash/manual/html_node/Programmable-Completion-Builtins.html#index-compopt
2012-12-19 10:46:50 +00:00
}
_gst_takes_arg() {
case "$1" in
-o|--output|--gst-debug-level|--gst-debug) true;;
--gst-plugin-path|--gst-plugin-load|--exclude) true;;
*) false;;
esac
}
tools/gstreamer-completion: Bash 3.2 compatibility fixes Compatible with bash 3.2; doesn't require the bash-completion package at all (though the easiest way to install this script is still to install bash-completion, and then drop this script into /etc/bash_completion.d). Note that bash 3 doesn't break COMP_WORDS according to characters in COMP_WORDBREAKS, so "property=val" looks like a single word, so this won't complete property values (on bash 3). Similarly, "--gst-debug-level=<TAB>" won't complete properly (on bash 3), but "--gst-debug-level <TAB>" will. For that reason, I now offer "--gst-debug-level" etc as completions instead of "--gst-debug-level=". Functions "_init_completion" and "_parse_help" were provided by the bash-completion package >= 2.0; now I roll my own equivalent of "_parse_help", and instead of "_init_completion" I use "_get_comp_words_by_ref" which is available from bash-completion 1.2 onwards. If the bash-completion package isn't available at all I use bash's raw facilities, at the expense of not completing properly when the cursor is in the middle of a word. The builtin "compopt" doesn't exist in bash 3; those users will just have to live with the inconvenience of "property=" completing to "property= " with a trailing space. Property values aren't completed properly anyway on bash 3 (see above). "[[ -v var ]]" to test whether a variable is set, also doesn't exist in bash 3. Neither does ";;&" to fall through in a "case" statement. In the unit tests: * On my system (OS X), "#!/bin/bash" is bash 3.2, whereas "#!/usr/bin/env bash" is the 4.2 version I built myself. * I have to initialise array variables like "expected=()", or bash 3 treats "+=" as appending to an array already populated with one empty string.
2012-12-21 08:56:26 +00:00
_gst_parse_help() {
$1 --help-all 2>&1 | grep -Eo -e '--[a-z-]+'
}
_gst_init_completion() {
if type _get_comp_words_by_ref &>/dev/null; then
# Available since bash-completion 1.2
_get_comp_words_by_ref cur cword prev words
else
# bash-completion not installed or too old. Use bash's raw facilities.
# This won't complete properly if the cursor is in the middle of a
# word.
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
cword=$COMP_CWORD
words=("${COMP_WORDS[@]}")
fi
}