Advanced LF Workflows: Integrating Shell Commands and Fuzzy Search

Getting Started with LF: Keyboard-Driven Terminal File ManagementLF (short for “list files”) is a lightweight, keyboard-driven terminal file manager inspired by tools like Ranger and nnn. It focuses on speed, simplicity, and extensibility, offering a minimal core with powerful customization through shell commands and scripts. This guide walks you through installation, basic usage, customization, and practical workflows so you can leverage LF for efficient file management in the terminal.


What is LF and why use it?

LF is a terminal-based file manager written in Go. It presents a two-column interface (directory listing and file preview by default) and emphasizes keyboard navigation over menus or mouse input. Choose LF if you want:

  • Fast, minimal UI that stays out of your way
  • Keyboard-driven workflow with vim-like navigation and custom keybindings
  • Extensibility through shell commands, scripts, and external tools
  • Portable, single-binary install with minimal dependencies

Installation

LF is distributed as a single binary, making installation straightforward.

  • macOS (Homebrew): brew install lf
  • Debian/Ubuntu: download prebuilt binary from releases or build from source; use dpkg when available
  • Arch Linux: pacman -S lf
  • From source: go install github.com/gokcehan/lf@latest

After installation, ensure the binary is in your PATH.


First launch and interface overview

Run lf in a terminal:

lf 

Default interface sections:

  • Left column: current directory listing
  • Right column: file preview (if configured)
  • Status bar: current path and selection info at the bottom

Navigation keys (default):

  • j / k — move down / up
  • h / l — go up one directory / enter directory or open file
  • gg / G — go to top / bottom
  • H / L — jump between panes (when using multiple)
  • / — start filtering the listing
  • : — enter command prompt (like in vim)

Files are displayed with basic colors and icons if configured.


Basic file operations

LF uses a small set of intuitive commands and keybindings for common tasks.

  • Open file: l or Enter (opens with $EDITOR or associated program)
  • Edit file: e (opens selected file in $EDITOR)
  • Copy: y (yank) then p (put) to paste into current directory
  • Move: d (delete from current listing) then p to paste — note: by default d marks for move; confirm behavior in your config
  • Delete: D (remove file) — prompts for confirmation depending on settings
  • Create directory: :mkdir dirname
  • Rename: :rename old new or R for inline rename (if configured)
  • Toggle selection: Space (select multiple files for batch operations)

Many actions can be run through the command prompt (:) using shell commands, e.g., :!cp %s /path/to/dest or :trash %f if you define a trash function.


Previews and file metadata

LF supports previews via a preview script or built-in less-like previewers. Common setup uses a previewer that:

  • Renders images as thumbnails (in terminals that support it)
  • Uses bat or highlight for syntax-highlighted file previews
  • Shows file metadata (size, permissions, mtime)

Example configuration to use bat for previews (assuming bat is installed) is shown in the config section below.


Configuration and customization

Configuration lives in ~/.config/lf/ by default. Key files:

  • lfrc — main config file for keybindings and commands
  • layouts — panel layouts
  • colors — colors and icons
  • rifle — file opener rules (which program opens which file type)

Create ~/.config/lf/lfrc to customize keybindings. Example lfrc snippets:

# open selected file with $EDITOR map e $EDITOR {file} # delete file with confirmation map D confirm rm -rf {file} 

Rifle is LF’s file opener that determines how files are opened. Sample rifle rule:

# open text files in $PAGER ext txt|md = $PAGER # images -> feh ext png|jpg = feh 

You can source scripts in lfrc and compose complex behaviors by calling shell functions or external scripts.


Integrating external tools

LF shines when combined with other CLI tools:

  • fd / fzf — fast file finding and fuzzy selection; bind a key to run fzf and cd to selection
  • bat — syntax-highlighted previews
  • ripgrep (rg) — content search, used with piping into LF or for in-place filtering
  • rsync — bind a copy/move operation for sync backups
  • tmux — open files in new panes/sessions directly from LF

Example: bind Ctrl-f to fzf finder and cd to selected path:

map <C-f> shell -f 'cd "$(fzf --preview "bat --style=numbers --color=always {}" )"' 

Example workflows

  1. Rapid navigation and editing
  • Use hjkl to move; Enter to open directory; e to edit files in your preferred editor.
  • Use / to filter for filenames quickly.
  1. Batch operations
  • Space-select multiple files, then press :!tar -czf archive.tar.gz %s to archive them (where %s expands to selected files).
  1. Search-and-open
  • Bind fzf to a key to fuzzy-find files across projects, preview with bat, press Enter to open in $EDITOR.
  1. Git-centric work
  • Add keybindings to run git status, git add -p on selected files, or open diffs in a split terminal.

Tips and best practices

  • Keep lfrc minimal and delegate complex logic to shell scripts—this keeps config readable.
  • Use rifle to define deterministic openers for file types rather than ad-hoc shell commands.
  • Learn a few powerful bindings (e.g., yank/put, filter, shell) and map them to ergonomically convenient keys.
  • Version-control your ~/.config/lf directory so you can reuse configs across machines.

Troubleshooting

  • Preview not showing: verify your previewer (bat/less) and that the preview script is executable.
  • Keybindings not taking effect: ensure lfrc is in ~/.config/lf/lfrc and check for syntax errors.
  • File associations wrong: edit rifle file to correct rules and reload LF.

Resources and further reading

  • LF GitHub repository for latest releases and issues
  • Example lfrc and rifle configs shared by the community on GitHub/Gist
  • Integration tutorials for fzf, bat, and tmux

LF gives a nimble, keyboard-first interface for file management in the terminal. Start by installing, customizing a few keybindings, and integrating one or two tools (bat, fzf). With small, focused scripts you can tailor LF into a powerful, efficient workflow that fits your daily tasks.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *