wiki/notebook/cli.fzf.org
Gabriel Arazas b088086b06 Merge evergreen notes into the notebook
Now, it's all under the notebook umbrella. Seems to be appropriate as it
is just my notes after all.

I also updated some notes from there. I didn't keep track of what it is
this time. Something about more learning notes extracted from my
"Learning how to learn" course notes and then some. Lack of time and
hurriness just makes it difficult to track but it should be under
version control already.
2021-07-21 16:28:07 +08:00

2.7 KiB

Command line: fzf

The family's favorite fuzzy finder. Basically, it takes a list then create an interface out of it. Not only it is easy to use and very flexible but also very configurable with the options to let you choose the keybindings and the previewer among other things.

Options

  • -m, --multi - enables multiple selection; by default, the keybinding to select is Tab
  • -p, --prompt - display the prompt message
  • --disabled - disable the search making fzf essentially a selection interface
  • --cycle - enables cyclic scrolling in the selection (it's annoying when it does not have those) If no input was passed, it will recursively list all of the files in the current directory. Pretty useful for a quick opening interface.

Examples

My favorite section where I get to show off some scripts featuring the star of the show. And also this is where everyone is going to go first.

Basic command-line file selection

fzf | xargs xdg-open

Quick manual page selection

apropos . \
    | fzf --multi --prompt "Choose manual(s) to open > " \
    | awk '{ print $1 "." gensub(/[()]/, "", "g", $2) }' \
    | xargs man

Goto directory with fzf and Bash

With my favorite find replacement, fd. It's a Bash function since you can't propagate directory changes with a script. Just have to put it somewhere in your configuration.

function fzf-cd() {
    local dir=${1:-$(pwd)}
    local dest=$(fd --type directory --hidden --base-directory "$dir" --follow | fzf --prompt "Where to go? > ")
    [[ $dest ]] && cd "$(realpath --logical "$dir")/$dest"
}

Even better when you bind it with a keyboard shortcut (e.g., bind '"\C-f":'fzf-cd\n"' on your Bash config).

Package selection in Arch Linux

Vanilla Arch, if that matters. You can do this on other operating systems as long as their package manager lets you list all of the packages either from your local database or from a remote server.

pacman -S --list --quiet \
    | fzf --multi --prompt "Install package(s) > " \
    | xargs doas pacman -S --noconfirm

Create an interactive tldr list

Have a tldr client (e.g., tealdeer) and bat installed.

tldr --list \
    | fzf --multi \
    | xargs --replace="{}" tldr {} \
    | bat