กลับไปหน้าสูตร
#zsh#shell#terminal#cheatsheet
Zsh Cheatsheet
รวมคำสั่งและเทคนิค Zsh แบบจัดเต็ม: history, globbing, aliases, functions, completion, prompt และ productivity
11 มีนาคม 2569อ่านประมาณ 1 นาที
สารบัญสูตร
Core Shortcuts
| Key | ใช้ทำอะไร |
|---|---|
Ctrl + A / E | ไปต้น/ท้ายบรรทัด |
Ctrl + U / K | ลบก่อน/หลัง cursor |
Ctrl + W | ลบคำก่อนหน้า |
Ctrl + R | search history |
Ctrl + L | clear screen |
History
| Command | ใช้ทำอะไร |
|---|---|
history | ดู history |
fc -l 1 | list history |
!! | รันคำสั่งล่าสุดซ้ำ |
!123 | รัน history ID |
!git | รันคำสั่งล่าสุดที่ขึ้นต้นด้วย git |
Globbing Power
| Pattern | ตัวอย่าง |
|---|---|
*.ts | ไฟล์ .ts ทั้งหมด |
**/*.md | recursive markdown files |
^*.log | ทุกไฟล์ยกเว้น .log |
*(.) | files only |
*(/) | dirs only |
Alias & Functions
alias ll='ls -la'
alias gs='git status -sb'
alias gp='git push'
mkcd() { mkdir -p "$1" && cd "$1"; }
extract() { tar -xvf "$1"; }
Useful .zshrc Snippet
export EDITOR="nvim"
export PATH="$HOME/.local/bin:$PATH"
setopt AUTO_CD HIST_IGNORE_DUPS SHARE_HISTORY
HISTSIZE=100000
SAVEHIST=100000
Completion & Plugins
| Feature | แนวทาง |
|---|---|
| completion | autoload -Uz compinit && compinit |
| autosuggestions | ใช้ plugin สำหรับแนะนำคำสั่ง |
| syntax highlight | plugin ช่วยอ่านคำสั่งผิดถูก |
| fzf integration | ค้นหาไฟล์/history เร็วขึ้น |