TechLead
Lesson 7 of 20
6 min read
DevTools & Productivity

Terminal Productivity

Master terminal workflows with aliases, functions, tmux, and command-line tools for 10x developer efficiency

The Terminal as Your Power Tool

The terminal is the most versatile tool in a developer's arsenal. While GUIs provide discoverability, the command line offers composability, automation, and speed. A developer who masters the terminal can perform complex operations in seconds that would take minutes through a graphical interface. This topic covers essential techniques to transform your terminal into a productivity powerhouse.

Essential Shell Navigation

# Cursor Movement (works in bash, zsh, and most shells)
Ctrl+A        # Move cursor to beginning of line
Ctrl+E        # Move cursor to end of line
Alt+B         # Move cursor back one word
Alt+F         # Move cursor forward one word
Ctrl+U        # Delete from cursor to beginning of line
Ctrl+K        # Delete from cursor to end of line
Ctrl+W        # Delete previous word
Alt+D         # Delete next word
Ctrl+Y        # Paste (yank) last deleted text
Ctrl+L        # Clear screen (same as 'clear')
Ctrl+R        # Reverse search through command history
Ctrl+S        # Forward search through command history
Ctrl+G        # Cancel search
Ctrl+C        # Cancel current command
Ctrl+Z        # Suspend current process (use 'fg' to resume)
!!            # Repeat last command
!$            # Last argument of previous command
!^            # First argument of previous command
!*            # All arguments of previous command

Useful Shell Aliases

Aliases let you create short names for long or frequently used commands. Add these to your ~/.zshrc or ~/.bashrc file.

# Navigation
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias ~="cd ~"
alias -- -="cd -"  # Go to previous directory

# Git shortcuts
alias g="git"
alias gs="git status"
alias ga="git add"
alias gc="git commit"
alias gp="git push"
alias gl="git log --oneline --graph --decorate -20"
alias gd="git diff"
alias gco="git checkout"
alias gb="git branch"
alias gf="git fetch --all --prune"
alias grc="git rebase --continue"
alias gra="git rebase --abort"

# Development
alias dev="npm run dev"
alias build="npm run build"
alias test="npm run test"
alias lint="npm run lint"

# System
alias ls="ls --color=auto"
alias ll="ls -alF"
alias la="ls -A"
alias l="ls -CF"
alias grep="grep --color=auto"
alias df="df -h"
alias du="du -h"
alias free="free -h"

# Quick edit configs
alias zshrc="code ~/.zshrc"
alias reload="source ~/.zshrc"

# Safety nets
alias rm="rm -i"
alias cp="cp -i"
alias mv="mv -i"

Shell Functions

For more complex operations, shell functions are more powerful than aliases because they can accept arguments and contain logic.

# Create directory and cd into it
mkcd() {
  mkdir -p "$1" && cd "$1"
}

# Git commit with message
gcm() {
  git add -A && git commit -m "$1"
}

# Find and kill process by port number
killport() {
  lsof -ti :"$1" | xargs kill -9 2>/dev/null
  echo "Killed process on port $1"
}

# Extract any archive format
extract() {
  case "$1" in
    *.tar.bz2) tar xjf "$1" ;;
    *.tar.gz)  tar xzf "$1" ;;
    *.bz2)     bunzip2 "$1" ;;
    *.rar)     unrar x "$1" ;;
    *.gz)      gunzip "$1" ;;
    *.tar)     tar xf "$1" ;;
    *.tbz2)    tar xjf "$1" ;;
    *.tgz)     tar xzf "$1" ;;
    *.zip)     unzip "$1" ;;
    *.7z)      7z x "$1" ;;
    *)         echo "Cannot extract '$1'" ;;
  esac
}

# Quick HTTP server in current directory
serve() {
  local port="${1:-3000}"
  npx serve -l "$port"
}

# Search file contents recursively
search() {
  grep -rn --color=auto "$1" "${2:-.}"
}

Modern CLI Replacements

Modern Rust-based CLI tools offer significant improvements over traditional Unix tools. They are faster, have better defaults, and provide more user-friendly output.

# Install modern CLI tools (macOS with Homebrew)
brew install eza     # Better 'ls' with icons, git status, tree view
brew install bat     # Better 'cat' with syntax highlighting and line numbers
brew install fd      # Better 'find' with intuitive syntax
brew install ripgrep # Better 'grep' (rg) - extremely fast search
brew install fzf     # Fuzzy finder for files, history, and more
brew install zoxide  # Better 'cd' that learns your habits
brew install delta   # Better git diff with syntax highlighting
brew install tldr    # Simplified man pages with practical examples
brew install jq      # JSON processor for the command line
brew install httpie  # Better curl with intuitive syntax

# Usage examples
eza -la --icons --git           # List files with icons and git status
eza --tree --level=3            # Tree view (replaces 'tree')
bat src/index.ts                # View file with syntax highlighting
fd ".tsx$" src/                # Find all .tsx files in src/
rg "useState" --type tsx        # Search for 'useState' in .tsx files
fzf                             # Interactive fuzzy file finder
z projects                      # Jump to most-used directory matching "projects"
http GET api.example.com/users  # Intuitive HTTP request
echo '{"name":"test"}' | jq .   # Pretty-print JSON

fzf (Fuzzy Finder) Integration

# Add to ~/.zshrc for fzf integration
# Ctrl+R uses fzf for history search
# Ctrl+T uses fzf for file search
# Alt+C uses fzf for directory navigation

# Custom fzf configuration
export FZF_DEFAULT_COMMAND='fd --type f --hidden --follow --exclude .git'
export FZF_DEFAULT_OPTS='--height 40% --layout=reverse --border'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"

# Git branch switcher with fzf
fbr() {
  local branch
  branch=$(git branch -a | fzf --query="$1" | sed 's/^[* ]*//' | sed 's/remotes/origin///')
  git checkout "$branch"
}

# Kill process interactively with fzf
fkill() {
  local pid
  pid=$(ps -ef | fzf --header-lines=1 | awk '{print $2}')
  [ -n "$pid" ] && kill -9 "$pid"
}

tmux for Session Management

tmux is a terminal multiplexer that lets you run multiple terminal sessions inside a single window, split panes, detach and reattach sessions, and keep processes running after disconnecting from SSH.

# tmux essentials (prefix key is Ctrl+B by default)
tmux new -s myproject     # Create a named session
tmux attach -t myproject  # Reattach to a session
tmux ls                   # List all sessions
tmux kill-session -t name # Kill a session

# Inside tmux (after Ctrl+B prefix):
Ctrl+B %     # Split pane vertically
Ctrl+B "     # Split pane horizontally
Ctrl+B arrow # Navigate between panes
Ctrl+B c     # Create new window
Ctrl+B n     # Next window
Ctrl+B p     # Previous window
Ctrl+B d     # Detach from session
Ctrl+B z     # Zoom/unzoom current pane
Ctrl+B [     # Enter scroll/copy mode (q to exit)

Terminal Productivity Tips

  • Use history search extensively: Ctrl+R with fzf integration is the fastest way to find and rerun past commands.
  • Pipe everything: Combine tools with pipes: rg "TODO" | wc -l counts TODOs, git log --oneline | fzf searches commits.
  • Use xargs: Transform output into arguments: fd ".test.ts" | xargs npx vitest run
  • Master job control: Ctrl+Z to suspend, fg to resume, bg to background, jobs to list.

Continue Learning