正在加载,请稍候…

Terminal Productivity: tmux, zsh, fzf, and Modern CLI Tools

Supercharge your terminal workflow with tmux, zsh plugins, fzf fuzzy finder, ripgrep, bat, and modern Unix tools for maximum development productivity.

Terminal Productivity Tools

tmux Configuration

# ~/.tmux.conf

# Remap prefix from C-b to C-a
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix

# Split panes
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"

# Pane navigation with vim keys
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R

# Window navigation
bind -n M-Left prev
bind -n M-Right next

# Reload config
bind r source-file ~/.tmux.conf ; display "Reloaded!"

# Mouse support
set -g mouse on

# 256 colors
set -g default-terminal "screen-256color"
set -ga terminal-overrides ",xterm-256color:Tc"

# Status bar
set -g status-position bottom
set -g status-bg colour234
set -g status-fg colour137
set -g status-left '#[fg=colour233,bg=colour241,bold] #S '
set -g status-right '#[fg=colour233,bg=colour241,bold] %H:%M '

# Session management
# New session: tmux new -s myproject
# List sessions: tmux ls
# Attach: tmux attach -t myproject
# Detach: C-a d

Tmux Shortcuts

# Session management
tmux new -s project          # New named session
tmux ls                      # List sessions
tmux attach -t project       # Attach to session
C-a d                        # Detach from session
C-a $                        # Rename session

# Window management
C-a c    # New window
C-a ,    # Rename window
C-a n/p  # Next/prev window
C-a [0-9] # Switch to window N

# Pane management
C-a |    # Split vertically
C-a -    # Split horizontally
C-a o    # Next pane
C-a z    # Zoom/unzoom pane
C-a q    # Show pane numbers
C-a x    # Kill pane

Zsh with Oh-My-Zsh

# Install Oh-My-Zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

# ~/.zshrc configuration
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="robbyrussell"

plugins=(
  git
  docker
  kubectl
  terraform
  aws
  fzf
  zsh-autosuggestions
  zsh-syntax-highlighting
  z  # Jump to directories by frecency
)

source $ZSH/oh-my-zsh.sh

# Useful aliases
alias ll='ls -lah'
alias ..='cd ..'
alias ...='cd ../..'
alias gs='git status'
alias gc='git commit'
alias gp='git push'
alias k='kubectl'
alias kns='kubectl config set-context --current --namespace'
alias tf='terraform'
alias dc='docker compose'

# Functions
mkcd() { mkdir -p "$1" && cd "$1"; }
fif() { grep --line-number --with-filename --no-messages -r "$1" .; }

fzf - Fuzzy Finder

# Install
brew install fzf
$(brew --prefix)/opt/fzf/install  # Install shell integrations

# Key bindings (after install)
Ctrl+T  # Fuzzy search files
Ctrl+R  # Fuzzy search command history
Alt+C   # Fuzzy search and cd to directory

# fzf with preview
fzf --preview 'bat --color=always {}'

# Custom functions
# Fuzzy checkout git branch
fbr() {
  git branch --all | grep -v HEAD | sed 's/.* //' | fzf-tmux -p |
    xargs git checkout
}

# Fuzzy kill process
fkill() {
  pid=$(ps -ax | grep -v "grep" | fzf -m | awk '{print $1}')
  [ -n "$pid" ] && echo "$pid" | xargs kill -${1:-9}
}

# Interactive git log
glf() {
  git log --oneline --decorate --all | fzf     --preview 'git show --stat --color=always {1}'     --bind 'enter:execute(git show {1})'
}

Modern CLI Replacements

# bat - cat with syntax highlighting
bat src/server.ts
bat --theme="Dracula" --style=numbers,changes file.py

# ripgrep - faster grep
rg "TODO" --type ts
rg "useState" --glob "*.tsx" -l  # List files only
rg "error" -A 3 -B 3 --color always  # Context lines

# fd - faster find
fd "*.ts" src/
fd -e py -x black {}  # Run black on all Python files

# eza - better ls
eza -la --git --icons
eza --tree --level=2

# delta - better git diff
# ~/.gitconfig
# [core]
#   pager = delta
# [delta]
#   side-by-side = true
#   line-numbers = true

# htop/btop - better top
btop

# jq - JSON processor
cat data.json | jq '.users[] | select(.active == true) | .name'
curl api.example.com/users | jq '.[0].email'

# httpie - better curl
http GET api.example.com/users Authorization:"Bearer token"
http POST api.example.com/users name="John" email="john@example.com"

Productivity Aliases

# ~/.zshrc additions

# Navigation
alias repos='cd ~/Documents/code'
alias dots='cd ~/dotfiles'
alias dl='cd ~/Downloads'

# Development
alias pn='pnpm'
alias nrd='npm run dev'
alias nrb='npm run build'
alias nrt='npm run test'
alias serve='python3 -m http.server 8000'

# Quick edit configs
alias vimrc='vim ~/.vimrc'
alias zshrc='vim ~/.zshrc && source ~/.zshrc'
alias hosts='sudo vim /etc/hosts'

# System
alias df='df -h'
alias du='du -sh *'
alias ports='lsof -i -P -n | grep LISTEN'
alias myip='curl ifconfig.me'
alias flush-dns='sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponder'

# Git
alias glog='git log --oneline --graph --decorate --all'
alias gundo='git reset HEAD~1 --soft'
alias gpf='git push --force-with-lease'