From 3259494d9e58b710592e34b0f739942f0f941acb Mon Sep 17 00:00:00 2001 From: Philip Langdale Date: Mon, 13 Jan 2020 17:10:51 -0800 Subject: 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. --- etc/mpv.bash-completion | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'etc') 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}")) -- cgit v1.2.3