cli-productivity
Included with Lifetime
$97 forever
Essential CLI tools and shell productivity patterns for efficient terminal workflows
devtoolsclishellproductivitybashzshterminaltools
What this skill does
# CLI Productivity Skill
Master essential CLI tools and shell patterns for efficient terminal workflows. This skill covers modern replacements for traditional Unix tools, fuzzy finding, pipeline patterns, and shell customization.
## When to Use This Skill
### USE when:
- Building efficient terminal workflows
- Processing text and JSON data
- Searching codebases quickly
- Navigating file systems efficiently
- Automating repetitive tasks
- Creating shell functions and aliases
- Building interactive scripts
### DON'T USE when:
- GUI-based workflows are more appropriate
- Processing binary data (use specialized tools)
- Complex data analysis (use Python/Pandas)
- Tasks requiring visual feedback
## Prerequisites
### Installation
**macOS (Homebrew):**
```bash
# Essential modern tools
brew install jq # JSON processor
brew install fzf # Fuzzy finder
brew install ripgrep # Fast grep (rg)
brew install fd # Fast find
brew install bat # Better cat
brew install exa # Better ls (or eza)
brew install zoxide # Smart cd
brew install starship # Shell prompt
brew install tmux # Terminal multiplexer
# Install fzf keybindings
$(brew --prefix)/opt/fzf/install
```
**Linux (Ubuntu/Debian):**
```bash
# Update package list
sudo apt-get update
# Install from apt (may be older versions)
sudo apt-get install -y jq fzf ripgrep fd-find bat
# Note: fd is 'fdfind' on Debian/Ubuntu
sudo ln -s $(which fdfind) /usr/local/bin/fd
# bat may be 'batcat' on older systems
sudo ln -s $(which batcat) /usr/local/bin/bat
# Install exa/eza
sudo apt-get install -y exa # or: cargo install eza
# Install zoxide
curl -sS https://raw.githubusercontent.com/ajeetdsouza/zoxide/main/install.sh | bash
# Install starship
curl -sS https://starship.rs/install.sh | sh
```
**Arch Linux:**
```bash
sudo pacman -S jq fzf ripgrep fd bat exa zoxide starship tmux
```
**Verification:**
```bash
# Verify installations
for cmd in jq fzf rg fd bat exa zoxide starship; do
command -v $cmd && echo "$cmd: OK" || echo "$cmd: NOT FOUND"
done
```
## Core Capabilities
### 1. jq - JSON Processing
**Basic Operations:**
```bash
# Pretty print JSON
echo '{"name":"John","age":30}' | jq '.'
# Extract field
curl -s https://api.github.com/repos/nodejs/node | jq '.stargazers_count'
# Filter arrays
echo '[1,2,3,4,5]' | jq '.[] | select(. > 2)'
# Transform data
echo '{"first":"John","last":"Doe"}' | jq '{fullName: (.first + " " + .last)}'
```
**Common jq Patterns:**
```bash
# Extract multiple fields
jq '{name: .name, stars: .stargazers_count}'
# Array operations
jq '.items | length' # Count items
jq '.items | first' # First item
jq '.items | last' # Last item
jq '.items[0:5]' # Slice first 5
# Filtering
jq '.[] | select(.status == "active")'
jq '.[] | select(.count > 100)'
jq '.[] | select(.name | contains("test"))'
# Sorting
jq 'sort_by(.date)'
jq 'sort_by(.date) | reverse'
# Grouping
jq 'group_by(.category)'
jq 'group_by(.category) | map({key: .[0].category, count: length})'
# Mapping
jq '.[] | {id, name}'
jq 'map({id: .id, upper_name: (.name | ascii_upcase)})'
```
**Shell Functions for jq:**
```bash
# Pretty print JSON file
jqp() {
jq '.' "$1" | bat --language json
}
# Extract field from JSON file
jqf() {
local file="$1"
local field="$2"
jq -r ".$field" "$file"
}
# Count items in JSON array
jqcount() {
jq 'if type == "array" then length else 1 end' "$1"
}
# Filter JSON by field value
jqfilter() {
local file="$1"
local field="$2"
local value="$3"
jq --arg val "$value" ".[] | select(.$field == \$val)" "$file"
}
```
### 2. fzf - Fuzzy Finder
**Basic Usage:**
```bash
# Find and edit file
vim $(fzf)
# Find with preview
fzf --preview 'bat --color=always {}'
# Multi-select
fzf --multi
# Filter with query
echo -e "apple\nbanana\norange" | fzf --query "an"
```
**fzf Configuration:**
```bash
# Add to ~/.bashrc or ~/.zshrc
# Default options
export FZF_DEFAULT_OPTS='
--height 40%
--layout=reverse
--border
--preview-window=right:50%:wrap
--bind=ctrl-d:preview-page-down
--bind=ctrl-u:preview-page-up
'
# Use fd for faster file finding
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
export FZF_ALT_C_COMMAND='fd --type d --hidden --follow --exclude .git'
# Preview settings
export FZF_CTRL_T_OPTS='--preview "bat --color=always --style=numbers --line-range=:500 {}"'
export FZF_ALT_C_OPTS='--preview "exa --tree --level=2 --color=always {}"'
```
**Powerful fzf Functions:**
```bash
# Fuzzy edit file
fe() {
local file
file=$(fzf --preview 'bat --color=always --style=numbers --line-range=:500 {}')
[[ -n "$file" ]] && ${EDITOR:-vim} "$file"
}
# Fuzzy cd into directory
fcd() {
local dir
dir=$(fd --type d --hidden --follow --exclude .git | fzf --preview 'exa --tree --level=2 --color=always {}')
[[ -n "$dir" ]] && cd "$dir"
}
# Fuzzy kill process
fkill() {
local pid
pid=$(ps aux | sed 1d | fzf --multi | awk '{print $2}')
[[ -n "$pid" ]] && echo "$pid" | xargs kill -9
}
# Fuzzy git checkout branch
fco() {
local branch
branch=$(git branch -a --color=always | grep -v '/HEAD' | fzf --ansi | sed 's/^[* ]*//' | sed 's#remotes/origin/##')
[[ -n "$branch" ]] && git checkout "$branch"
}
# Fuzzy git log
flog() {
git log --oneline --color=always | fzf --ansi --preview 'git show --color=always {1}' | awk '{print $1}'
}
# Fuzzy history search
fh() {
local cmd
cmd=$(history | fzf --tac | sed 's/^[ ]*[0-9]*[ ]*//')
[[ -n "$cmd" ]] && eval "$cmd"
}
# Fuzzy environment variable
fenv() {
local var
var=$(env | fzf | cut -d= -f1)
[[ -n "$var" ]] && echo "${!var}"
}
# Fuzzy docker container
fdocker() {
local container
container=$(docker ps --format '{{.Names}}\t{{.Image}}\t{{.Status}}' | fzf | awk '{print $1}')
[[ -n "$container" ]] && docker exec -it "$container" sh
}
```
### 3. ripgrep (rg) - Fast Search
**Basic Usage:**
```bash
# Search for pattern
rg "function"
# Case insensitive
rg -i "error"
# Show line numbers
rg -n "TODO"
# Search specific file types
rg --type py "import"
rg -t js "require"
# Exclude patterns
rg "pattern" --glob '!*.min.js'
rg "pattern" --glob '!node_modules'
```
**Advanced ripgrep:**
```bash
# Context lines
rg -C 3 "error" # 3 lines before and after
rg -B 2 "error" # 2 lines before
rg -A 2 "error" # 2 lines after
# Fixed strings (no regex)
rg -F "func()"
# Word boundaries
rg -w "log" # Match "log" not "logging"
# Multiple patterns
rg -e "pattern1" -e "pattern2"
# Files matching pattern
rg -l "TODO" # List files only
rg -c "TODO" # Count matches per file
# Inverse match
rg -v "DEBUG" # Lines NOT containing DEBUG
# Replace
rg "old" --replace "new"
# JSON output
rg --json "pattern" | jq '.'
# Statistics
rg --stats "pattern"
```
**ripgrep Functions:**
```bash
# Search and preview with fzf
rgs() {
rg --color=always --line-number "$1" | fzf --ansi --preview 'bat --color=always $(echo {} | cut -d: -f1) --highlight-line $(echo {} | cut -d: -f2)'
}
# Search and open in editor
rge() {
local selection
selection=$(rg --color=always --line-number "$1" | fzf --ansi)
if [[ -n "$selection" ]]; then
local file=$(echo "$selection" | cut -d: -f1)
local line=$(echo "$selection" | cut -d: -f2)
${EDITOR:-vim} "+$line" "$file"
fi
}
# Search TODOs
todos() {
rg --color=always "TODO|FIXME|HACK|XXX" "${1:-.}" | fzf --ansi
}
# Search function definitions
funcs() {
rg --color=always "^(def |function |async function |const .* = |class )" "${1:-.}" | fzf --ansi
}
```
### 4. fd - Fast Find
**Basic Usage:**
```bash
# Find files by name
fd "readme"
# Find with extension
fd -e md
fd -e py -e js
# Find directories
fd -t d "src"
# Find fRelated in devtools
raycast-alfred
IncludedmacOS launcher automation with Raycast extensions (TypeScript/React) and Alfred workflows (AppleScript/Python) for keyboard-driven productivity
devtools
vscode-extensions
IncludedVS Code productivity optimization with essential extensions, settings sync, profiles, keybindings, snippets, and workspace configuration
devtools
docker
IncludedComplete Docker containerization patterns for development and production workflows
devtools
git-advanced
IncludedAdvanced git workflows including rebase, worktrees, bisect, hooks, and monorepo patterns
devtools
pyproject-toml
IncludedConfigure Python projects with pyproject.toml for modern packaging, tools, and dependency management
devtools
uv-package-manager
IncludedUV for fast Python package management, virtual environments, and project workflows
devtools