mirror of https://github.com/mpv-player/mpv
bash completion: Cache the options list
The bash completion seems to be working decently at this point, so I feel comfortable caching the options output to improve the performance of the completion.
This commit is contained in:
parent
18070f7405
commit
8676f4616c
|
@ -17,9 +17,12 @@
|
||||||
# License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
# License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
||||||
#
|
#
|
||||||
|
|
||||||
|
# Cache all the mpv options
|
||||||
|
_mpv_options=$(mpv --list-options)
|
||||||
|
|
||||||
_mpv_get_args()
|
_mpv_get_args()
|
||||||
{
|
{
|
||||||
local doc=$(mpv --list-options | grep -E "^\\s*$1\\s")
|
local doc=$(echo "$_mpv_options" | grep -E "^\\s*$1\\s")
|
||||||
local partial="$2"
|
local partial="$2"
|
||||||
local type=$(echo "$doc" | awk '{print $2;}')
|
local type=$(echo "$doc" | awk '{print $2;}')
|
||||||
|
|
||||||
|
@ -70,6 +73,11 @@ _mpv_get_args()
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# This regex detects special options where we don't want an '=' appended
|
||||||
|
_mpv_special_regex='Flag.*\[not in config files\]|Print'
|
||||||
|
_mpv_regular_options=($(echo "$_mpv_options" | grep -v -E "$_mpv_special_regex" |awk '{print "\\"$1;}' | grep '\--'))
|
||||||
|
_mpv_special_options=($(echo "$_mpv_options" | grep -E "$_mpv_special_regex" |awk '{print "\\"$1;}' | grep '\--'))
|
||||||
|
|
||||||
_mpv()
|
_mpv()
|
||||||
{
|
{
|
||||||
compopt +o nospace mpv
|
compopt +o nospace mpv
|
||||||
|
@ -90,14 +98,9 @@ _mpv()
|
||||||
else
|
else
|
||||||
case $cur in
|
case $cur in
|
||||||
-*)
|
-*)
|
||||||
# This regex detects special options where we don't want an '=' appended
|
COMPREPLY=($(compgen -W "${_mpv_regular_options[*]}" -S '=' -- "${cur}"))
|
||||||
local special_regex='Flag.*\[not in config files\]|Print'
|
|
||||||
local options=($(mpv --list-options | grep -v -E "$special_regex" |awk '{print "\\"$1;}' | grep '\--'))
|
|
||||||
local specials=($(mpv --list-options | grep -E "$special_regex" |awk '{print "\\"$1;}' | grep '\--'))
|
|
||||||
|
|
||||||
COMPREPLY=($(compgen -W "${options[*]}" -S '=' -- "${cur}"))
|
|
||||||
local normal_count=${#COMPREPLY[@]}
|
local normal_count=${#COMPREPLY[@]}
|
||||||
COMPREPLY+=($(compgen -W "${specials[*]}" -- "${cur}"))
|
COMPREPLY+=($(compgen -W "${_mpv_special_options[*]}" -- "${cur}"))
|
||||||
if [ $normal_count -gt 0 -o ${#COMPREPLY[@]} -gt 1 ]; then
|
if [ $normal_count -gt 0 -o ${#COMPREPLY[@]} -gt 1 ]; then
|
||||||
compopt -o nospace mpv
|
compopt -o nospace mpv
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue