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

No autocompletion by normal install FZF #2542

Closed
5 tasks
theCollectiv opened this issue Jun 25, 2021 · 5 comments
Closed
5 tasks

No autocompletion by normal install FZF #2542

theCollectiv opened this issue Jun 25, 2021 · 5 comments

Comments

@theCollectiv
Copy link

theCollectiv commented Jun 25, 2021

  • [ x] I have read through the manual page (man fzf)
  • [ x] I have the latest version of fzf
  • [ x] I have searched through the existing issues

Info

  • OS
    • [x ] Linux
    • Mac OS X
    • Windows
    • Etc.
  • Shell
    • [ x] bash
    • zsh
    • fish

Problem / Steps to reproduce

I'm using a pretty normal ubuntu version

❯ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.2 LTS
Release:	20.04
Codename:	focal
❯ uname -a
Linux logos 5.4.0-77-generic #86-Ubuntu SMP Thu Jun 17 02:35:03 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

and bash as shell

❯ echo $SHELL
/bin/bash

Installed FZF via
sudo apt-get install fzf

❯ fzf --version
0.20.0

I have no experience in using fzf and checked the normal stuff. FZF is working fine by command. Really great and I like it.
I did add to the bashrc

export FZF_DEFAULT_COMMAND='rg --files --hidden --follow --no-ignore-vcs'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_DEFAULT_OPTS='--height 40% --layout=reverse --border --preview "cat {}"'

But the autocompletion doesn't word like
cd **[tab] -> nothing happens
and the Key bindings (CTRL-T, CTRL-R, and ALT-C) neither.

So I checked out these threads, but couldn't find a solution to get it working.
#872
#227

In these threads are mentioned:

❯ complete | grep cd$
complete -o nospace -F _cd cd

And

❯ complete -o nospace -o plusdirs -F _fzf_dir_completion cd

~ 

got the following result
❯ cd **bash: completion: Funktion _fzf_dir_completion' nicht gefunden. (Funktion_fzf_dir_completion' nicht gefunden. -> Function `_fzf_dir_completion' not found.)

I was a little confused and thought that something else was interacting with FZF. But I got the same results, when I'm doing the same on my laptop (same Ubuntu, same installation of FZF; no bashrc edited) instead of my desktop.

Maybe its up to me and I can't figure it out, how to get it work. But normally it should work by default, I guess. Someone else here with the same/similar problem?

PS.: Maybe this issue (#2480) is related too (but different ubuntu -> 21.04)

@theCollectiv
Copy link
Author

theCollectiv commented Jun 27, 2021

My bad. I didn't read this page to the point where ...
https://github.com/junegunn/fzf#using-linux-package-managers

Key bindings (CTRL-T / CTRL-R / ALT-C) and fuzzy auto-completion may not be enabled by default.

Refer to the package documentation for more information. (e.g. apt-cache show fzf)

Doing so, it says:

❯ apt-cache show fzf
...to long didnt read...
...
 Refer /usr/share/doc/fzf/README.Debian for quick instructions on how to
 add keybindings for Bash, Zsh, Fish to call fzf.

Going there /usr/share/doc/fzf/README.Debian:

Bash
====

Append this line to ~/.bashrc to enable fzf keybindings for Bash:

   source /usr/share/doc/fzf/examples/key-bindings.bash

Append this line to ~/.bashrc to enable fuzzy auto-completion for Bash:

   source /usr/share/doc/fzf/examples/completion.bash

Adding these lines to the bashrc did solve the problem. Everything is working fine and how it should work (ALT C, cd **, etc.pp.).

@ianchanning
Copy link

ianchanning commented Oct 26, 2021

For Fedora the solution is the similar /usr/share/doc/fzf/README.Fedora but subtly different:

To enable shell key bindings, source the applicable script from
/usr/share/fzf/shell from your shell initialization. For example, use
/usr/share/fzf/shell/key-bindings.bash in ~/.bashrc for user-wide bash.

The addition of the auto-completion and actual code you can copy and paste in the README.Debian file is really helpful. So this description works for Fedora:

Append this line to ~/.bashrc to enable fzf keybindings for Bash:

   source /usr/share/fzf/shell/key-bindings.bash

There doesn't appear to be any auto-completion for Fedora bash.

Also the Fedora dnf -C info fzf command misses the handy Refer to /usr/share/doc/fzf/README.Fedora ... in its output.

@TravelTrader
Copy link

For me, it also doesn't work but I did the above steps (Ubuntu/Debian here):

  • I have read through the manual page (man fzf)
  • I have the latest version of fzf
  • I have searched through the existing issues

Info

  • OS
    • Linux
    • Mac OS X
    • Windows
    • Etc.
  • Shell
    • bash
    • zsh
    • fish

Problem / Steps to reproduce

For gnome-terminal the completion and keybindings did not work after the installation. And now when using source /usr/share/doc/fzf/examples/completion.bash as it's written in the README.Debian in the command line, it works (cd **<tab>). But when adding the same line in .bashrc or using

if [ -f /usr/share/doc/fzf/examples/completion.bash ]; then
    . /usr/share/doc/fzf/examples/completion.bash
fi

in the same way .bash_aliases is integrated, it doesn't work.

In short, how can I add the source ... in the .bashrc to get it work without using source ... before every session?

Thank you very much for your help!

@TravelTrader
Copy link

Solved with a hint of the irc-channel #bash by putting the implementation at the end of .bashrc and now it works perfectly.

@ilorez
Copy link

ilorez commented Mar 21, 2024

Everything for me working great but i have a question
How i can make auto complete working without (Ctrl+R)?
For example if i write

sudo

It's should give me a auto complete with mute color to that command (if was last one that i used)

sudo apt update

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants