How to prevent recursive calls to fzf in custom bash completion? #4695
Replies: 1 comment 1 reply
-
|
The recursion happens because sourcing .bashrc again runs fzf s setup which overwrites the original completion function, but your wrapper still calls that name, now pointing to fzf s wrapper again. Fix: guard your wrapper so it only installs once. In ~/foo_completion.sh: if [ -z "$__foo_orig" ]; then Also in .bashrc, guard fzf sourcing: if ! declare -f _fzf_setup_completion >/dev/null; then These prevent double-wrapping and recursion. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm writing my own tiny completion framework for a project of mine, and sourcing
~/.bashrctwice is breaking completion.In my
~/.bashrcI setup fzf's path completion forfoo:# ~/.bashrc ... _fzf_setup_completion path fooI decide that
fooshould have a flag--barand define it in the file~/foo_completion.sh. To preserve existent fzf's completion (or any other it might be) I parse the current completion function, call it, and updateCOMPREPLYwith--bar.For this to take effect I update my
~/.bashrcto source this file after the fzf's completion.It works, now I have access to both completions.
The problem is, when I source
~/.bashrcagain, an attempt to completefoomakes what looks like a recursive call that crashes the session.Is this the correct approach?
Also tried inverting the order to first source my completion file and then fzf's, but the problem persists.
Beta Was this translation helpful? Give feedback.
All reactions