Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix performance #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 33 additions & 2 deletions zsh/fzf-zsh-completion.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,25 @@ _fzf_completion() {

# all except autoload functions
local __full_variables="$(typeset -p)"
local __full_functions="$(functions + | "$_fzf_bash_completion_grep" -F -vx -e "$(functions -u +)")"
local __full_functions="$(
{
echo '#START#' # Add markers to ensure we process complete lines
functions +
echo '#MID#'
functions -u +
echo '#END#'
} | \
awk -v RS='\n' '
$0=="#START#" { mode="load"; next }
$0=="#MID#" { mode="auto"; next }
$0=="#END#" { exit }
mode=="load" { loaded[$0] = 1 }
mode=="auto" && ($0 in loaded) { delete loaded[$0] }
END {
for (f in loaded) print f
}
'
)"
local __autoload_variables="$(typeset + | "$_fzf_bash_completion_grep" -F -e 'undefined ' | "$_fzf_bash_completion_awk" '{print $NF}')"

# do not allow grouping, it stuffs up display strings
Expand Down Expand Up @@ -120,7 +138,20 @@ _fzf_completion() {
__stderr="$(
_fzf_completion_preexit() {
trap -
functions + | "$_fzf_bash_completion_grep" -F -vx -e "$(functions -u +)" -e "$__full_functions" | while read -r f; do which -- "$f"; done >&"${__evaled}"
local -a new_funcs=() known_funcs=()
new_funcs=("${(@f)$(functions +)}")
known_funcs=("${(@f)$(functions -u +)}")
known_funcs+=("${(f)__full_functions}")

local -A func_map=()
for f in "${known_funcs[@]}"; do
[[ -n "$f" ]] && func_map[$f]=1
done

for f in "${new_funcs[@]}"; do
[[ -n "$f" && -z "${func_map[$f]}" ]] && which -- "$f"
done >&"${__evaled}"

# skip local and autoload vars
{ typeset -p -- $(typeset + | "$_fzf_bash_completion_grep" -vF -e 'local ' -e 'undefined ' | "$_fzf_bash_completion_awk" '{print $NF}' | "$_fzf_bash_completion_grep" -vFx -e "$__autoload_variables") | "$_fzf_bash_completion_grep" -xvFf <(printf %s "$__full_variables") >&"${__evaled}" } 2>/dev/null
}
Expand Down