fzf icon indicating copy to clipboard operation
fzf copied to clipboard

Configuring Key Bindings and Fuzzy Auto-Completion in Ubuntu 22.04

Open cvladan opened this issue 2 years ago • 6 comments

It's simply astonishing how challenging it is to get this working on the most popular Linux distribution, especially given that the documentation is far from clear and straightforward. That's why I've decided to write this up.

To be specific, my system is Ubuntu 22.04, my shell of choice is bash, and I'm on Oracle Cloud.

Everything should be achieved easily by running:

sudo apt -y install fzf

But alas!

1. Not enabled by default

It's essential to know that on Debian-based distributions like Ubuntu is, key bindings (Ctrl+T / Ctrl+R / Alt+C) and fuzzy auto-completion are not enabled by default. You must add them in your ~/.bashrc.

echo '[ -f /usr/share/doc/fzf/examples/key-bindings.bash ] && source /usr/share/doc/fzf/examples/key-bindings.bash' >> ~/.bashrc
echo '[ -f /usr/share/bash-completion/completions/fzf ] && source /usr/share/bash-completion/completions/fzf' >> ~/.bashrc

2. Files are Not Downloaded + Latest Version Has Fatal Error

Everything would have been simple if those files were present - but they aren't. Not only are they missing, but the current file key-bindings.bash is also faulty as it is responsible for throwing an error unknown option: --scheme=history on Ctrl-T. So you'll need an older version (commit: 6dcf5c3).

You'll have to manually download them and store them where they're supposed to be:

if [[ ! -f /usr/share/doc/fzf/examples/completion.bash ]]; then
  sudo curl https://raw.githubusercontent.com/junegunn/fzf/master/shell/completion.bash -o /usr/share/doc/fzf/examples/completion.bash
  curl https://raw.githubusercontent.com/junegunn/fzf/6dcf5c3d7d6c321b17e6a5673f1533d6e8350462/shell/key-bindings.bash -o /usr/share/doc/fzf/examples/key-bindings.bash
fi

3. Just One More Re-login Cycle

Lastly, to get all of this sourced into the system, it's easiest for me to open a new session and test it.


It's Slightly Easier for Zsh

For the .zsh shell, just alter the file extensions everywhere to .zsh and there's no older version required - I guess this, but I didn't actually test it:

if [[ ! -f /usr/share/doc/fzf/examples/completion.zsh ]]; then
  sudo curl https://raw.githubusercontent.com/junegunn/fzf/master/shell/completion.zsh -o /usr/share/doc/fzf/examples/completion.zsh
  sudo curl https://raw.githubusercontent.com/junegunn/fzf/master/shell/key-bindings.zsh -o /usr/share/doc/fzf/examples/key-bindings.zsh
fi

In summary, a serious nuisance

Isn't there a way to make this simpler?

cvladan avatar Aug 10 '23 06:08 cvladan

You might want to contact the maintainers of the package instead (I'm not one of them).

but the current file key-bindings.bash is also faulty

There is no problem with the file. You're getting the error because you're using it with an old version of fzf binary which doesn't have the --scheme option.

junegunn avatar Aug 10 '23 11:08 junegunn

Possible, but that is the fzf version that gets installed with apt install fzf, which is why I wrote these instructions.

cvladan avatar Aug 10 '23 12:08 cvladan

I know, that should be an old version and you can't use the latest scripts on this repo with it.

junegunn avatar Aug 10 '23 15:08 junegunn

In any case, thousands of users want to use fzf key bindings on Ubuntu, and this is the easiest and possibly the only way to do it.

This is also the recommended method for installing fzf on Linux, and without these instructions that I have written down, it is NOT possible to use key bindings on Ubuntu.

I also think that this should be written somewhere in the installation instructions, but in the meantime I have documented it here for everyone - as the amount of effort required to set this up really surprised me.

It's not about where to report a bug, but the idea is that people can use this feature, and they should have the instructions written in one place, not scattered across multiple issues in multiple repos.

I suppose we don't want to say "you can't use the fzf key bindings on Ubuntu"?

cvladan avatar Aug 11 '23 08:08 cvladan

You're suggesting that the Ubuntu package needs fixing, but posting it here won't trigger any action from the actual maintainers.

I have used Ubuntu in the past, and I have always struggled with the outdated packages it provides. You end up coming to terms with the limitation of the default package manager and looking for other ways to install newer versions of the package. (e.g. building from source, using alternative package managers such as Homebrew, etc.)

This is also the recommended method for installing fzf on Linux, and without these instructions that I have written down, it is NOT possible to use key bindings on Ubuntu.

There are other ways to install fzf on Linux and they're mentioned in https://github.com/junegunn/fzf#installation. If the package from the default package manager is broken or if you need a different (newer) version than it provides, you will have to use another way.

junegunn avatar Aug 11 '23 08:08 junegunn

@cvladan Please, file your bug report at https://bugs.launchpad.net/ubuntu/+filebug where it belongs.

mcepl avatar Oct 15 '23 18:10 mcepl

yes, there is a mixture of old fzf and git cloned one. apt remove fzf works for me.

xiuliren avatar Mar 11 '24 07:03 xiuliren

I'm going to close this because it's not a bug in fzf. It's a bug in the Ubuntu package, and/or it's caused by a misconfiguration.

As of fzf 0.48.0, the scripts are embedded in the binary. So the users are less likely to have incompatibility problems.

See #3675

junegunn avatar Mar 14 '24 01:03 junegunn