Open-Source Wikis

/

fzf

/

Fun facts

junegunn/fzf

Fun facts

A few oddities and trivia from the fzf codebase.

The oldest surviving code is not in Go

The first commit landed on 2013-10-24 ("Initial commit") and originally contained a Ruby implementation of fzf. The 2015 Go rewrite replaced the entire program, but the test harness under test/ is still Ruby (test/runner.rb, test/test_core.rb, etc.). So while no original Ruby production code survives, the idea and most of the integration tests ride a Ruby interpreter every time make itest runs.

The longest file is the terminal

src/terminal.go clocks in at 8,205 lines, more than half of the Go core. It owns key parsing, the action engine, the preview window, the placeholder language, the screen layout for header/footer/list/border/input, the mouse handling, the --listen integration, the bracketed paste protocol, the passthrough escape-sequence handling for sixel/iterm2/kitty image protocols, and more. It is a known refactoring target — but every new UI feature also lands here, which is why it keeps growing.

The runner-up is src/options.go at 3,954 lines of hand-written CLI parsing and option validation.

Avoiding net/http saves 2.4 MB

A comment at the top of the HTTP server in src/server.go records the binary-size impact of using a stdlib HTTP server vs. a hand-rolled one:

* No --listen:            2.8MB
* --listen with net/http: 5.7MB
* --listen w/o net/http:  3.3MB

That's why fzf parses HTTP requests by hand with bufio.Scanner and a regex. The author would rather write the parser than ship an extra ~2.4 MB to every user.

ASCII art at the top of the shell scripts

Every shell integration script begins with this banner:

#     ____      ____
#    / __/___  / __/
#   / /_/_  / / /_
#  / __/ / /_/ __/
# /_/   /___/_/ key-bindings.bash

It sits in shell/key-bindings.bash, shell/key-bindings.zsh, shell/key-bindings.fish, and the matching completion files.

The walker has a story about z:

src/reader.go contains a long comment about a symlink loop:

When following symlinks, precompute the absolute real paths of walker roots so we can skip symlinks that point to an ancestor. fastwalk's built-in loop detection (shouldTraverse) catches loops on the second pass, but a single pass through a symlink like z: -> / already traverses the entire root filesystem, causing severe resource exhaustion.

That guard exists because under WSL/MSYS, the Windows drive Z: often shows up as a symlink to /, and a naive walker would happily walk the entire host filesystem before noticing.

Generated string tables

src/actiontype_string.go and src/tui/eventtype_string.go are both produced by go generate invoking golang.org/x/tools/cmd/stringer. The action-type table is so long that it serves as an informal census of every keybindable command fzf supports — over 200 entries, from actAccept through actUnix-line-discipline (actUnixLineDiscipline).

A matcher's complexity

The matcher in src/matcher.go partitions the chunk list across runtime.NumCPU() goroutines (or --threads N) and gives each one a pre-allocated Slab of 16-bit and 32-bit scratch buffers (src/util/slab.go, slab16Size / slab32Size in src/constants.go). This is the only place the algo package's V2 algorithm allocates — so on warm runs, sorting through millions of items is essentially free of garbage-collector pressure.

Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.

Fun facts – fzf wiki | Factory