From 218b3c8274193c7ea128d164c7924fcb46c2db65 Mon Sep 17 00:00:00 2001 From: Tomas Janousek Date: Wed, 11 Nov 2020 11:13:41 +0000 Subject: [PATCH] [bash-completion] Move -F/_fzf filter to __fzf_orig_completion_filter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This prevents mistakes like the one fixed by the previous commit, and also speeds bash startup a tiny bit: before: $ HISTFILE=/tmp/bashhist hyperfine 'bash --rcfile shell/completion.bash -i' Benchmark #1: bash --rcfile shell/completion.bash -i Time (mean ± σ): 22.4 ms ± 0.6 ms [User: 28.7 ms, System: 7.8 ms] Range (min … max): 21.7 ms … 25.2 ms 123 runs after: $ HISTFILE=/tmp/bashhist hyperfine 'bash --rcfile shell/completion.bash -i' Benchmark #1: bash --rcfile shell/completion.bash -i Time (mean ± σ): 21.2 ms ± 0.3 ms [User: 24.9 ms, System: 6.4 ms] Range (min … max): 20.7 ms … 23.3 ms 132 runs --- shell/completion.bash | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/completion.bash b/shell/completion.bash index 5d82b65..1af1769 100644 --- a/shell/completion.bash +++ b/shell/completion.bash @@ -47,7 +47,7 @@ __fzf_comprun() { } __fzf_orig_completion_filter() { - sed 's/^\(.*-F\) *\([^ ]*\).* \([^ ]*\)$/export _fzf_orig_completion_\3="\1 %s \3 #\2"; [[ "\1" = *" -o nospace "* ]] \&\& [[ ! "$__fzf_nospace_commands" = *" \3 "* ]] \&\& __fzf_nospace_commands="$__fzf_nospace_commands \3 ";/' | + sed '/ -F/!d; / _fzf/d; s/^\(.*-F\) *\([^ ]*\).* \([^ ]*\)$/export _fzf_orig_completion_\3="\1 %s \3 #\2"; [[ "\1" = *" -o nospace "* ]] \&\& [[ ! "$__fzf_nospace_commands" = *" \3 "* ]] \&\& __fzf_nospace_commands="$__fzf_nospace_commands \3 ";/' | awk -F= '{OFS = FS} {gsub(/[^A-Za-z0-9_= ;]/, "_", $1);}1' } @@ -307,7 +307,7 @@ a_cmds=" # Preserve existing completion eval "$(complete | - sed -E '/-F/!d; / _fzf/d; '"/ ($(echo $d_cmds $a_cmds | sed 's/ /|/g; s/+/\\+/g'))$/"'!d' | + sed -E "/ ($(echo $d_cmds $a_cmds | sed 's/ /|/g; s/+/\\+/g'))$/"'!d' | __fzf_orig_completion_filter)" if type _completion_loader > /dev/null 2>&1; then @@ -353,7 +353,7 @@ _fzf_setup_completion() { return 1 fi shift - eval "$(complete -p "$@" 2> /dev/null | sed '/-F/!d; / _fzf/d' | __fzf_orig_completion_filter)" + eval "$(complete -p "$@" 2> /dev/null | __fzf_orig_completion_filter)" for cmd in "$@"; do case "$kind" in dir) __fzf_defc "$cmd" "$fn" "-o nospace -o dirnames" ;;