percol
Interactive grep/filter tool for UNIX pipes.
Official WebsiteFeatures
Installation
pip install percolWhy use percol?
percol is a powerful interactive grep/filter tool that enhances your command-line workflow. It allows you to filter any text stream interactively with regex support, making it perfect for processing command outputs efficiently.
Interactive Filtering
Filter any text stream interactively in real-time. See results update as you type, making it easy to find exactly what you need.
Regex Support
Full regular expression support for powerful pattern matching. Use Python regex syntax for complex filtering scenarios.
Pipe-friendly
Works seamlessly with Unix pipes. Chain any command output through percol for interactive filtering.
Customizable
Customize keybindings and behavior to match your preferences. Configuration via Python scripts.
Installation
# Using pip (recommended)
pip install percol
# Using Homebrew (macOS)
brew install percol
# Using apt (Ubuntu/Debian)
sudo apt install percol
# Using Pacman (Arch Linux)
sudo pacman -S percolpercol requires Python 3.x. Install via pip for the latest version.
Basic Usage
Filter Command Output
# Filter lines from any command
ls -la | percol
# Search through files with grep
grep -r "pattern" . | percol
# Filter process list
ps aux | percol
# Filter network connections
netstat -tulpn | percol
# Select from environment variables
env | percolPractical Examples
# Kill a process interactively
ps aux | percol | awk '{print $2}' | xargs kill -9
# Edit a file from find results
find . -type f | percol | xargs vim
# Switch git branches
git branch | percol | awk '{print $1}' | xargs git checkout
# SSH into a server
grep "^Host " ~/.ssh/config | awk '{print $2}' | percol | xargs ssh
# Browse command history
history | percol | awk '{print $2-}'
# Select docker container
docker ps | percol | awk '{print $1}'Regular Expression Filtering
# Filter with regex (search for pattern)
cat /var/log/syslog | percol --query "error|warning"
# Case-insensitive search
cat file.txt | percol -i
# Match lines starting with specific pattern
ps aux | percol --query "^root"
# Match lines ending with specific pattern
ls -l | percol --query ".txt$"
# Exclude pattern (using percol's filtering)
cat log.txt | percolIntegration with Shell
Add percol functions to your shell configuration for convenient access to common filtering tasks.
# ~/.bashrc or ~/.zshrc
# Kill process interactively
pkill() {
local pid
pid=$(ps aux | percol | awk '{print $2}')
if [ ! -z "$pid" ]; then
kill -9 "$pid"
fi
}
# Switch git branch with percol
gb() {
git branch | percol | awk '{print $1}' | xargs git checkout
}
# Edit file from find with percol
ef() {
find . -type f | percol | xargs ${EDITOR:-vim}
}
# SSH into host from config
ssh-percol() {
grep "^Host " ~/.ssh/config | awk '{print $2}' | percol | xargs ssh
}
# Browse docker containers
docker-percol() {
docker ps | percol | awk '{print $1}' | xargs docker exec -it
}
# Select from command history
hist() {
history | percol | awk '{print $2-}' | xargs
}
# Change directory from find
cdf() {
cd "$(find . -type d | percol)"
}Default Keybindings
| Key | Action |
|---|---|
| Ctrl+J / Down | Move to next item |
| Ctrl+K / Up | Move to previous item |
| Enter | Select and output current item |
| Ctrl+C / Esc | Cancel and exit |
| Ctrl+U | Clear query string |
| Ctrl+W | Delete word from query |
| Tab | Toggle selection (with -m flag) |
Common Options
# Case-insensitive matching
cat file.txt | percol -i
# Multi-selection mode
ls | percol -m
# Use initial query
ps aux | percol -q "python"
# Suppress output of unselected items
echo "test" | percol --no-unselected
# Configure with Python script
percol --rcfile ~/.percol.d/percol.conf
# Show prompt
cat file.txt | percol --prompt "Filter: "
# Don't sort results
ps aux | percol --no-sort
# Invert match (select items NOT matching)
cat log.txt | percol --invert-matchConfiguration
Create a configuration file for percol at ~/.percol.d/percol.conf
# ~/.percol.d/percol.conf
# percol configuration file in Python
# Keybindings
percol.view.PROMPT = 'Filter: '
# Change key bindings
import percol.actions as acts
from percol.key_binding import add_keybinding, remove_keybinding
# Use 'j' to move down and 'k' to move up
add_keybinding(acts.move_down, 'j')
add_keybinding(acts.move_up, 'k')
# Use 'l' for select and Enter for cancel
add_keybinding(acts.finish, 'l')
remove_keybinding(acts.finish, 'C-m')
# Emacs-like keybindings
add_keybinding(acts.move_down, 'C-n')
add_keybinding(acts.move_up, 'C-p')
add_keybinding(acts.move_beginning_of_line, 'C-a')
add_keybinding(acts.move_end_of_line, 'C-e')
# Coloring
percol.view.StyleDict = {
'default': ('white', 'default'),
'highlighted': ('red', 'default'),
'matched': ('yellow', 'default'),
}Advanced Patterns
# Multi-select mode for batch operations
ps aux | percol -m | awk '{print $2}' | xargs kill -9
# Combining with other tools
find . -name "*.log" | percol | xargs tail -f
# Using with git log
git log --oneline | percol | awk '{print $1}' | xargs git show
# Filter and count
cat access.log | percol | wc -l
# Extract specific field after filtering
df -h | percol | awk '{print $1}' | xargs mount
# Complex regex filtering
journalctl | percol -q 'ERROR|WARN|CRITICAL'
# Pipe to another tool
ls -la | percol | awk '{print $NF}' | xargs fileTips
- •percol is lighter and simpler than fzf, making it great for systems where you want minimal dependencies
- •Use Python regex patterns in your queries for powerful filtering - full Python
remodule support - •Combine multiple filters by piping:
command | percol | percol - •The
-mflag enables multi-selection, useful for batch operations withxargs - •Create aliases for your most common percol commands to speed up your workflow
- •Percol's Python-based configuration allows for complex customization compared to shell-based tools
- •Works well in scripts and automation - output goes directly to stdout for piping