From 8676f4616c6673c34cd265c738eb0fa31ef3ccdb Mon Sep 17 00:00:00 2001 From: Philip Langdale Date: Sat, 8 Feb 2020 08:59:56 -0800 Subject: 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. --- etc/mpv.bash-completion | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'etc') diff --git a/etc/mpv.bash-completion b/etc/mpv.bash-completion index 7557956ff5..1a824cb690 100644 --- a/etc/mpv.bash-completion +++ b/etc/mpv.bash-completion @@ -17,9 +17,12 @@ # License along with mpv. If not, see . # +# Cache all the mpv options +_mpv_options=$(mpv --list-options) + _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 type=$(echo "$doc" | awk '{print $2;}') @@ -70,6 +73,11 @@ _mpv_get_args() 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() { compopt +o nospace mpv @@ -90,14 +98,9 @@ _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}")) + COMPREPLY=($(compgen -W "${_mpv_regular_options[*]}" -S '=' -- "${cur}")) 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 compopt -o nospace mpv fi -- cgit v1.2.3