brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: fzf Alt-C jumps into any subdirectory with a fuzzy search

Linux and shell
~/tips/tip-fzf-alt-c-cd

eval "$(fzf --bash)"

Use fzf's Alt-C binding to change directory with fuzzy search.

Typing cd and then a long path one tab at a time gets old quickly. If fzf is already installed for Ctrl-R, I’d use its other two key bindings as well.

Load the shell integration once in your shell config:

# ~/.bashrc
eval "$(fzf --bash)"
# ~/.zshrc
source <(fzf --zsh)

After that, Alt-C opens a fuzzy list of the directories below the current one. Type a few letters of the name, press Enter, and the shell changes into it. Ctrl-T does the same for files and pastes the chosen path onto your command line, so vim followed by Ctrl-T is a quick way to open something deep in a project.

A caveat: on a Mac, Alt only works as a key combination when Terminal or iTerm treats Option as Meta. Otherwise Option-C just types a special character. Also, the lists start in the current directory, so on a huge tree they take a moment unless you set FZF_ALT_C_COMMAND to something faster, like an fd command.

One more detail: fzf also has a --height 40% option that keeps the picker small and inline instead of taking over the whole screen. Put it in FZF_DEFAULT_OPTS and every binding follows.

Further reading: fzf on GitHub, shell integration

More Linux and shell tips zoxide query -ls project comm --total a.txt b.txt diff -r -x .git -x '*.log' one two printf '%s\n' a b c d e f | xargs -n1 -P3 --process-slot-var=SLOT sh -c 'echo "slot $SLOT got $0"; sleep 0.2' patch -R g.txt < f.patch All Linux and shell tips (178) All topics

Link