fzf-tmux: script to open fzf in a tmux pane
2015. 03. 08.

(In case you don't know what fzf is: fzf is a command-line fuzzy finder that works as a grep-like Unix filter. This screencast will give you the idea of how it can be used)

fzf is an ncurses program so it starts in fullscreen mode, but it's not always desirable. One can use tmux split panes to make fzf take only a small portion of the screen estate and I really like the idea, but doing so has required some cumbersome scripting so far.

So I wrote this fzf-tmux script and added to the repository. fzf-tmux a small wrapper script for fzf and it works just like fzf, except that it launches the finder in a new tmux pane.

# usage: fzf-tmux [-u|-d [HEIGHT[%]]] [-l|-r [WIDTH[%]]] [--] [FZF OPTIONS]
# -[udlr] for up/down/left/right

find ~ | fzf-tmux -r 30%

A good example would be to use it for checking out Git branches. A typical Git repository does not have many number of branches, so fzf taking up the entire screen is not ideal. Using fzf-tmux -d 15 can improve the situation. (d is for down)

# fbr - checkout git branch
fbr() {
  local branches branch
  branches=$(git branch) &&
  branch=$(echo "$branches" | fzf-tmux -d 15 +m) &&
  git checkout $(echo "$branch" | sed "s/.* //")
}

See:

(When you're not on tmux, fzf-tmux will silently ignore -[udlr] options and simply fall back to the default behavior, so you can invariably use it in your scripts.)

I've always thought that the obligatory fullscreen mode of fzf was its major drawback. But now with this fzf-tmux script, it's trivial to start fzf either in a split pane of any size on any position (up, down, left, right), and it does not leave incidental artifacts on your terminal unlike the other similar tools such as selecta. So I'm starting to feel that fzf not trying to control the layout by itself and delegating the responsibility to a better suited tool, in this case tmux, better follows the Unix philosophy. ("Do one thing well!")

Anyway, the script is now on fzf repository, and you can get it by a git-pull. I also recommend rerunning the install script as fzf 0.9.4 has a backward incompatible change.

cd ~/.fzf && git pull && ./install

Or if you're like me and manage fzf using vim-plug like follows:

Plug 'junegunn/fzf', { 'do': 'yes \| ./install' }

a simple :PlugUpdate fzf will do.

I'll probably release a new version on Homebrew as well. Please try it and let me know of any issues you run into. Thanks.

» capture | close