diff options
author | Philip Langdale <philipl@overt.org> | 2020-02-08 08:59:56 -0800 |
---|---|---|
committer | Philip Langdale <philipl@overt.org> | 2020-02-08 09:50:58 -0800 |
commit | 8676f4616c6673c34cd265c738eb0fa31ef3ccdb (patch) | |
tree | 7409a81d3dd52015de5b2368aa9d6e467a7352a1 | |
parent | 18070f7405cdb1cf6a7629879591af12bec43f11 (diff) | |
download | mpv-8676f4616c6673c34cd265c738eb0fa31ef3ccdb.tar.bz2 mpv-8676f4616c6673c34cd265c738eb0fa31ef3ccdb.tar.xz |
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.
-rw-r--r-- | etc/mpv.bash-completion | 19 |
1 files changed, 11 insertions, 8 deletions
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 <http://www.gnu.org/licenses/>. # +# 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 |