summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorPhilip Langdale <philipl@overt.org>2020-01-13 17:10:51 -0800
committerPhilip Langdale <philipl@overt.org>2020-01-13 17:12:25 -0800
commit3259494d9e58b710592e34b0f739942f0f941acb (patch)
tree8f33ca24c63c5b839a3577f0d3ece845a6a3240d /etc
parent4d516601953be45e6771ce0c26d8df1a6890b6fc (diff)
downloadmpv-3259494d9e58b710592e34b0f739942f0f941acb.tar.bz2
mpv-3259494d9e58b710592e34b0f739942f0f941acb.tar.xz
bash completion: only generate option list when needed
Right now we are generating the fully option list before doing anything else. That makes filename completion significantly slower than it was before, for no gain. It's easy to only generate the option list when it's actually needed. I also know I could additionally cache the option list across invocations, but I'm not doing that yet to make testing easier.
Diffstat (limited to 'etc')
-rw-r--r--etc/mpv.bash-completion10
1 files changed, 5 insertions, 5 deletions
diff --git a/etc/mpv.bash-completion b/etc/mpv.bash-completion
index b49ae423ef..7557956ff5 100644
--- a/etc/mpv.bash-completion
+++ b/etc/mpv.bash-completion
@@ -74,11 +74,6 @@ _mpv()
{
compopt +o nospace mpv
- # This regex detects special options where we don't want an '=' appended
- 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 '\--'))
-
# _filedir requires the current candidate be in $cur
local cur=${COMP_WORDS[COMP_CWORD]}
local prev=${COMP_WORDS[((COMP_CWORD - 1))]}
@@ -95,6 +90,11 @@ _mpv()
else
case $cur in
-*)
+ # This regex detects special options where we don't want an '=' appended
+ 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[@]}
COMPREPLY+=($(compgen -W "${specials[*]}" -- "${cur}"))