junegunn/fzf
Shell integration
The shell/ directory contains key bindings and fuzzy completion scripts for Bash, Zsh, and Fish. The Go binary embeds them via //go:embed and prints them when invoked with --bash, --zsh, or --fish. The recommended setup line is:
# bash
eval "$(fzf --bash)"
# zsh
source <(fzf --zsh)
# fish
fzf --fish | sourceFiles
shell/
├── common.sh # Helpers shared across bash + zsh
├── completion.bash # bash fuzzy completion
├── completion.zsh # zsh fuzzy completion
├── completion.fish # fish fuzzy completion
├── key-bindings.bash # Ctrl-T / Ctrl-R / Alt-C for bash
├── key-bindings.zsh # ditto for zsh
├── key-bindings.fish # ditto for fish
└── update.sh # Splices common.sh into per-shell scriptsThe shell scripts are also included in the binary as embedded []byte slices in main.go:
//go:embed shell/key-bindings.bash
var bashKeyBindings []byte
//go:embed shell/completion.bash
var bashCompletion []byte
// ... and similar for zsh, fish, and the man pageKey bindings
| Binding | Effect |
|---|---|
Ctrl-T |
Pick file paths under the current directory and insert at the cursor. |
Ctrl-R |
Pick a command from shell history. |
Alt-C |
Pick a directory and cd into it. |
Each binding has corresponding *_COMMAND and *_OPTS env vars to override the source command and the fzf options:
FZF_CTRL_T_COMMAND,FZF_CTRL_T_OPTSFZF_CTRL_R_COMMAND,FZF_CTRL_R_OPTSFZF_ALT_C_COMMAND,FZF_ALT_C_OPTS
The bindings in shell/key-bindings.bash, key-bindings.zsh, and key-bindings.fish are intentionally similar in shape; they all call into __fzf_select__, __fzf_history__, and __fzf_cd__ (or shell-equivalent functions).
Fuzzy completion
The completion scripts override the shell's tab-completion machinery. Typing **<TAB> (the configurable FZF_COMPLETION_TRIGGER) anywhere on the command line opens fzf with a relevant source list:
| Context | Source |
|---|---|
cd **<TAB>, pushd **<TAB> |
Directories. |
vim **<TAB>, cat **<TAB>, generic file completion |
Files and directories. |
kill **<TAB> |
Process IDs. |
ssh **<TAB>, telnet **<TAB> |
Hostnames from ~/.ssh/config, /etc/hosts. |
unset **<TAB>, export **<TAB>, unalias **<TAB> |
Environment variables / aliases. |
| Custom | Defined via _fzf_complete_<command>. |
Bash and Zsh share most of the implementation; the splicing is done by shell/update.sh. Fish has a separate, narrower implementation because of fish's different completion API.
Tunable env vars include FZF_COMPLETION_TRIGGER, FZF_COMPLETION_OPTS, FZF_COMPLETION_PATH_OPTS, and FZF_COMPLETION_DIR_OPTS.
How common.sh is shared
shell/common.sh defines __fzf_defaults, __fzf_exec_awk, and other helpers. The bash and zsh scripts splice it inline using markers:
#----BEGIN INCLUDE common.sh
# NOTE: Do not directly edit this section, which is copied from "common.sh".
# To modify it, one can edit "common.sh" and run "./update.sh" to apply
# the changes. See code comments in "common.sh" for the implementation details.
...
#----END INCLUDEshell/update.sh rewrites the include blocks; make fmt invokes it; make lint runs shell/update.sh --check to catch out-of-sync edits.
Tests
test/test_shell_integration.rb drives all three shells through tmux (the CI installs bash zsh fish for this). Tests assert that Ctrl-T/Ctrl-R/Alt-C produce the expected output and that completion replaces the trigger correctly.
Useful environment variables
FZF_DEFAULT_COMMAND— used by all key bindings as the default source if the per-binding*_COMMANDis unset.FZF_DEFAULT_OPTS/FZF_DEFAULT_OPTS_FILE— default flags applied to every fzf invocation.FZF_TMUX/FZF_TMUX_HEIGHT/FZF_TMUX_OPTS— when set, the bindings invokefzf-tmuxinstead offzfso the picker pops in a tmux split.FZF_COMPLETION_TRIGGER— change**<TAB>to your preferred sequence.
Where it lives
| Concern | File |
|---|---|
| Bash key bindings | shell/key-bindings.bash |
| Bash completion | shell/completion.bash |
| Zsh key bindings | shell/key-bindings.zsh |
| Zsh completion | shell/completion.zsh |
| Fish key bindings | shell/key-bindings.fish |
| Fish completion | shell/completion.fish |
| Shared helpers | shell/common.sh |
| Splicing tool | shell/update.sh |
| Embedding | main.go (//go:embed) |
| Tests | test/test_shell_integration.rb |
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.