
终端生产力工具
tmux 配置
# ~/.tmux.conf
# 将前缀键从 C-b 改为 C-a
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
# 分割窗格
bind | split-window -h -c "#{pane_current_path}"
bind - split-window -v -c "#{pane_current_path}"
# 使用 vim 键导航窗格
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
# 窗口导航
bind -n M-Left prev
bind -n M-Right next
# 重新加载配置
bind r source-file ~/.tmux.conf \; display "已重新加载!"
# 鼠标支持
set -g mouse on
# 256 色
set -g default-terminal "screen-256color"
set -ga terminal-overrides ",xterm-256color:Tc"
# 状态栏
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 '
# 会话管理
# 新建会话:tmux new -s myproject
# 列出会话:tmux ls
# 附加会话:tmux attach -t myproject
# 分离会话:C-a d

Tmux 快捷键
# 会话管理
tmux new -s project # 新建命名会话
tmux ls # 列出会话
tmux attach -t project # 附加到会话
C-a d # 分离当前会话
C-a $ # 重命名会话
# 窗口管理
C-a c # 新建窗口
C-a , # 重命名窗口
C-a n/p # 下一个/上一个窗口
C-a [0-9] # 切换到窗口 N
# 窗格管理
C-a | # 垂直分割
C-a - # 水平分割
C-a o # 下一个窗格
C-a z # 放大/还原窗格
C-a q # 显示窗格编号
C-a x # 关闭窗格

Zsh 与 Oh-My-Zsh
# 安装 Oh-My-Zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# ~/.zshrc 配置
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="robbyrussell"
plugins=(
git
docker
kubectl
terraform
aws
fzf
zsh-autosuggestions
zsh-syntax-highlighting
z # 按频率跳转目录
)
source $ZSH/oh-my-zsh.sh
# 实用别名
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'
# 函数
mkcd() { mkdir -p "$1" && cd "$1"; }
fif() { grep --line-number --with-filename --no-messages -r "$1" .; }

fzf - 模糊搜索
# 安装
brew install fzf
$(brew --prefix)/opt/fzf/install # 安装 shell 集成
# 快捷键(安装后)
Ctrl+T # 模糊搜索文件
Ctrl+R # 模糊搜索命令历史
Alt+C # 模糊搜索并 cd 到目录
# 带预览的 fzf
fzf --preview 'bat --color=always {}'
# 自定义函数
# 模糊切换 git 分支
fbr() {
git branch --all | grep -v HEAD | sed 's/.* //' | fzf-tmux -p |
xargs git checkout
}
# 模糊终止进程
fkill() {
pid=$(ps -ax | grep -v "grep" | fzf -m | awk '{print $1}')
[ -n "$pid" ] && echo "$pid" | xargs kill -\${1:-9}
}
# 交互式 git 日志
glf() {
git log --oneline --decorate --all | fzf \
--preview 'git show --stat --color=always {1}' \
--bind 'enter:execute(git show {1})'
}
现代 CLI 替代工具
# bat - 带语法高亮的 cat
bat src/server.ts
bat --theme="Dracula" --style=numbers,changes file.py
# ripgrep - 更快的 grep
rg "TODO" --type ts
rg "useState" --glob "*.tsx" -l # 仅列出文件
rg "error" -A 3 -B 3 --color always # 上下文行
# fd - 更快的 find
fd "*.ts" src/
fd -e py -x black {} # 对所有 Python 文件运行 black
# eza - 更好的 ls
eza -la --git --icons
eza --tree --level=2
# delta - 更好的 git diff
# ~/.gitconfig
# [core]
# pager = delta
# [delta]
# side-by-side = true
# line-numbers = true
# htop/btop - 更好的 top
btop
# jq - JSON 处理器
cat data.json | jq '.users[] | select(.active == true) | .name'
curl api.example.com/users | jq '.[0].email'
# httpie - 更好的 curl
http GET api.example.com/users Authorization:"Bearer token"
http POST api.example.com/users name="John" email="john@example.com"
生产力别名
# ~/.zshrc 补充
# 导航
alias repos='cd ~/Documents/code'
alias dots='cd ~/dotfiles'
alias dl='cd ~/Downloads'
# 开发
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'
# 快速编辑配置
alias vimrc='vim ~/.vimrc'
alias zshrc='vim ~/.zshrc && source ~/.zshrc'
alias hosts='sudo vim /etc/hosts'
# 系统
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'