Editor's Choice Forums

Bash command line :: fzf

FZF is quite a nifty tool that integrates into your command line shell and provides a lookup / shortcut facility, similar to the “tab” auto-complete but more extensive. Installing It appears in most modern distributions, however the dist...

FZF is quite a nifty tool that integrates into your command line shell and provides a lookup / shortcut facility, similar to the “tab” auto-complete but more extensive.

Installing

It appears in most modern distributions, however the distro versions can be quite out of date, so you might prefer to install it directly from the git repository.

git clone --depth 1 https://github.com/junegunn/fzf.git ~/.fzf
~/.fzf/install

Once you’e done this, you may need to restart your terminal session for the changes to kick in, but once active you’ll have access to a number of new shortcuts.

ls

So when you’re looking to list the files in a given location, you can now list a double asterisk as the location, then hit tab, and it will give you an altogether new and different auto-complete experience;

Screenshot from 2024-04-20 12-48-37

What it will offer you is a cursor key operated list of possibilities, and as you type, it will narrow down the search list.

Screenshot from 2024-04-20 12-49-00

Now this is really quick, there are 250,000 files in my home folder and it scanned them all in a second or two. Select the file you want, then hit return.

(any command) CTRL+T

For example, type in “vi” then CTRL+T (not literally, hold down control and press T) and it will pop up the same sort of selection.

(any command) ALT+C

As per CTRL+T but just lists folders (directories). Note that both CTRL+T and ALT+C work “without” a command if you just want to browse files or folders.

cd

So cd works in the same way as “ls”, the difference is that the list offered consists only of folders with files excluded.

Screenshot from 2024-04-20 12-55-57

Other than the graphical element, what makes this so interesting is that is the recursive nature of the listing and the fact you can interactively search before making a selection. i.e. it doesn’t list all the folders in your current folder, it lists all the folders in the tree of folders “under” your current folder.

kill

Now I hear you ask, how can you make “kill” more interesting … well, how about like this, type “kill **” then hit tab;

Just select the process you want to kill and hit return. If you want to get a little more from it, there are key combinations that will let you select a number of processes if you want to kill more than one.

ssh

Yup, it does ssh too! Try typing “ss **” then tab;

Screenshot from 2024-04-20 13-01-02

Same principle, select the host you want to ssh to and hit return. It looks like this is fed from recent hosts. Although I’ve not checked where it’s getting it’s history from, given it’s showing 80 for me, it’s doing more than looking in .ssh/config.

Summary

fzf is a flexible addition to modern shells that enhances file and folder selection. If you do a lot of command line work, maybe worth a look.

Click to view the poll.

1 post - 1 participant

Read full topic