Terminal Productivity — tmux, Zsh, Fish, Alias
Tối ưu terminal workflow: tmux cho session management, Zsh/Fish plugins, alias hữu ích và CLI tools.
Terminal là công cụ chính của developer. Tối ưu nó — tối ưu cả ngày làm việc.
Shell — Chọn Đúng#
Zsh — Mặc Định Trên macOS#
Zsh là shell mặc định trên macOS và hầu hết Linux distro mới.
Oh My Zsh — framework quản lý plugin và theme:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"bashPlugin nên có (trong ~/.zshrc):
plugins=(
git # Git aliases: gst, gco, gaa, ...
zsh-autosuggestions # Gợi ý lệnh từ history
zsh-syntax-highlighting # Tô màu lệnh
docker # Docker completion
npm # Npm completion
history # Tìm kiếm history
)bashFish — User-Friendly#
Fish có syntax highlighting, autosuggestion, và web config ngay từ đầu:
# Cài Fish
brew install fish
# Mở web config
fish_config
# Prompt đẹp
fisher install matchai/spacefishbashtmux — Terminal Multiplexer#
tmux cho phép nhiều terminal trong một cửa sổ, session tồn tại cả khi mất kết nối SSH.
Basic Commands#
# Session
tmux new -s myproject # Tạo session mới
tmux ls # List session
tmux attach -t myproject # Attach vào session
tmux kill-session -t myproject
# Trong tmux (prefix: Ctrl+b)
Ctrl+b % # Split vertical
Ctrl+b " # Split horizontal
Ctrl+b arrow # Di chuyển giữa các pane
Ctrl+b c # New window
Ctrl+b n/p # Window tiếp/trước
Ctrl+b d # Detach (session vẫn chạy)
Ctrl+b [ # Scroll modebashCấu Hình (~/.tmux.conf)#
# Mouse support
set -g mouse on
# Tăng history
set -g history-limit 50000
# Prefix đổi thành Ctrl+a (dễ với tay)
set -g prefix C-a
# 256 color
set -g default-terminal "screen-256color"bashAlias — Tiết Kiệm Gõ Phím#
# Git
alias gs="git status"
alias gc="git commit"
alias gp="git push"
alias gco="git checkout"
alias gl="git log --oneline --graph --decorate"
# Navigation
alias ..="cd .."
alias ...="cd ../.."
alias ~="cd ~"
# Docker
alias dps="docker ps"
alias dcd="docker compose down"
alias dcu="docker compose up -d"
# List
alias ll="ls -lah"
alias la="ls -A"
alias tree="find . -maxdepth 2 -type d | sort"bashHistory Tricks#
# Tìm kiếm history
Ctrl+r # Search history (fuzzy)
history | grep docker
# Chạy lại lệnh
!! # Lệnh cuối
!$ # Tham số cuối của lệnh trước
!docker # Lệnh docker gần nhất
!100 # Chạy lệnh số 100 trong history
# Sửa lệnh trước
^old^new # Thay thếbashCLI Tools Siêu Hữu Ích#
File & Navigation#
# fd — thay thế find (nhanh hơn)
fd "*.ts" # Tìm file .ts
fd -e md -x wc -l # Tìm .md và chạy wc
# bat — thay thế cat (có syntax highlight)
bat file.ts # Xem file với highlight
bat -n file.ts # Hiện số dòng
# ripgrep (rg) — thay thế grep (siêu nhanh)
rg "function" --type ts
rg "TODO" --glob '!node_modules'
# eza — thay thế ls (đẹp hơn)
eza -la --icons
eza --tree # Tree view
# zoxide — cd thông minh (học thói quen)
z myproject # Nhảy đến project
z blog # cd đến ~/w/dopana/blogbashProcess & System#
# htop — thay thế top
htop
# duf — thay thế df
duf
# procs — thay thế ps
procs
# bottom (btm) — thay thế htop + nhiều hơn
btmbashNetwork#
# httpie — thay thế curl cho API
http GET https://api.example.com/users
http POST https://api.example.com/users name=Alice
# ngrok — tunnel localhost ra internet
ngrok http 3000
# dog — thay thế dig
dog example.combashJSON#
# jq — xử lý JSON trong terminal
cat data.json | jq '.users[] | {name, email}'
curl api.example.com/users | jq '.[0:3]'
# fx — JSON viewer tương tác
curl api.example.com/users | fxbashFZF — Fuzzy Finder#
FZF cho phép tìm kiếm mờ trong terminal:
# Cài
brew install fzf
# Tìm file và mở
vim $(fzf)
# Git branch switcher
gco $(git branch | fzf | tr -d ' *')
# Docker container kill
docker stop $(docker ps | fzf | awk '{print $1}')
# History search
history | fzfbashKeybindings Custom#
# VS Code style trong terminal
bindkey "^P" history-search-backward
bindkey "^N" history-search-forward
bindkey "^A" beginning-of-line
bindkey "^E" end-of-line
bindkey "^K" kill-line
bindkey "^U" kill-whole-line
bindkey "^W" backward-kill-wordbashWorkflow — Terminal IDE#
tmux session "myproject"
├── Window 1: Editor (Neovim)
│ ├── Pane 1: Code
│ └── Pane 2: Terminal
├── Window 2: Server
│ └── Pane 1: npm run dev
└── Window 3: Git
└── Pane 1: git log, git statusplaintextCài Đặt Nhanh#
# macOS
brew install \
tmux \
fzf \
fd \
ripgrep \
bat \
eza \
zoxide \
httpie \
jq \
htop
# Oh My Zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
# Fish
brew install fishbashKết Luận#
Terminal productivity là đầu tư một lần — lợi ích mỗi ngày. Bắt đầu với:
- Oh My Zsh + plugins autosuggestions + syntax-highlighting
- tmux cho session management
- Alias cho git và docker
- fzf cho fuzzy finding
- fd + rg + bat — thay thế find/grep/cat