CLI Workflows: Practical Terminal Patterns
Command-line tools are most powerful when they work together. This guide explains how to combine popular utilities like ripgrep, fzf, bat, and Git to build repeatable terminal workflows that save time and reduce friction.
Why CLI workflows matter
A single tool can solve a narrow problem, but the real value of the terminal comes from composition. Well-designed CLI workflows make it easy to:
- find the right file or symbol quickly
- preview content before editing
- edit text in context
- reuse the same pattern in many projects
Core workflow principles
All good terminal workflows follow a few simple rules:
- Prefer pipes to move structured data between tools.
- Make output human-readable so you can verify results before changing files.
- Use filters to narrow results before taking action.
- Automate safely with preview steps and small, incremental changes.
Workflow 1: Search, preview, edit
When you need to locate a symbol and inspect it before editing, combine:
- ripgrep for fast project search
- fzf for fuzzy selection
- bat for readable previews
rg --line-number TODO | fzf --delimiter : --preview 'bat --style=numbers --color=always {1} --highlight-line {2}'This command finds TODO comments, lets you choose the match with fzf, and previews the file around the selected line with bat. If the result is the right file, open it in your editor or continue the workflow.
Workflow 2: Find and replace with confidence
Use the search-only step first, then run the replacement after reviewing matches:
rg --line-number 'oldFunctionName' --glob '!node_modules/*'When the matches look correct, replace safely with a preview-first workflow:
rg --files-with-matches 'oldFunctionName' | xargs -I{} sh -c 'bat --style=numbers --color=always {} | sed -n "1,20p"'Finally, make the edit in the editor or use a tool like perl -pi -e only after verification.
Workflow 3: Jump to files with fzf and git
Discover changed files and open them quickly from the current repo:
git status --short | fzf --preview 'bat --style=numbers --color=always {1}'This pattern helps you inspect staged or modified files before committing changes.
Workflow 4: Build reusable shell functions
Encapsulate common workflows in shell functions or scripts so you can reuse them without typing long pipelines each time.
# ~/.bashrc or ~/.zshrc
rgf() {
rg --line-number "$1" --glob '!node_modules/*' | fzf --delimiter : --preview 'bat --style=numbers --color=always {1} --highlight-line {2}'
}
Then run rgf TODO anywhere in the repo.
Related tools
This workflow guide is most effective when paired with these pages:
When not to use CLI workflows
- Non-text data: use dedicated GUI tools for images, video, or complex binary formats.
- Large files: some very large files are better inspected with specialized log analysis tools.
- Team training: avoid overly custom shell functions if your team prefers shared tooling and documentation.
Next steps
To make these workflows productive on your machine, invest in a small dotfiles setup, add aliases for frequently used commands, and keep the terminal environment predictable. The more you reuse the same patterns, the more value you get from the CLI.