Cài đặt Oh My Zsh (macOS, Windows, Linux) + zsh-syntax-highlighting & zsh-autocomplete


💡 Bài này hướng dẫn cài Zsh + Oh My Zsh theo thứ tự cho macOS → Windows → Linux, kèm 2 plugin:

  • zsh-syntax-highlighting

  • zsh-autocomplete

Có cả phần Theme & Font, chỉnh .zshrc, rồi chạy source để áp dụng.

0) Điều kiện chung (áp dụng cho cả 3 hệ)

  • Cần có: zsh, git, curl
  • Kiểm tra nhanh:
echo $SHELL
zsh --version

1) macOS

1.1 Cài Zsh (nếu chưa có)

macOS thường đã có zsh sẵn. Nếu muốn cài bản mới qua Homebrew:

brew install zsh git

Đặt zsh làm shell mặc định:

chsh -s "$(which zsh)"

Đóng Terminal/iTerm2 rồi mở lại.

1.2 Cài Oh My Zsh

sh -c "$(curl -fsSL 
https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
)"

1.3 Cài plugin: zsh-syntax-highlighting, zsh-autocomplete

git clone 
https://github.com/zsh-users/zsh-syntax-highlighting.git
 \
  ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

git clone --depth 1 
https://github.com/marlonrichert/zsh-autocomplete.git
 \
  ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autocomplete

1.4 Cài Theme & Font

Font (khuyến nghị): cài font có hỗ trợ Powerline/Nerd Font.

  • Ví dụ: MesloLGS NF hoặc bất kỳ Nerd Font.
  • Sau khi cài font, vào Terminal/iTerm2 Settings → Profiles → Text → Font để chọn.

Theme (khuyến nghị): powerlevel10k

git clone --depth=1 
https://github.com/romkatv/powerlevel10k.git
 \
  ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

2) Windows

Trên Windows, cách ổn định nhất để dùng Oh My Zsh là WSL (Windows Subsystem for Linux).

2.1 Cài WSL + Ubuntu

Mở PowerShell (Admin):

wsl --install

Khởi động lại máy nếu được yêu cầu. Sau đó mở Ubuntu (WSL) và làm tiếp các bước giống Linux (mục 3).

2.2 Theme & Font trên Windows Terminal

  • Cài Nerd Font (ví dụ: MesloLGS NF)
  • Mở Windows Terminal → Settings → Profiles → Ubuntu → Appearance → Font face và chọn font vừa cài

3) Linux (Ubuntu/Debian; distro khác làm tương tự)

3.1 Cài Zsh + git + curl

sudo apt update
sudo apt install -y zsh git curl

Đặt zsh làm shell mặc định:

chsh -s "$(which zsh)"

Đăng xuất và đăng nhập lại (hoặc mở terminal mới).

3.2 Cài Oh My Zsh

sh -c "$(curl -fsSL 
https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
)"

3.3 Cài plugin: zsh-syntax-highlighting, zsh-autocomplete

git clone 
https://github.com/zsh-users/zsh-syntax-highlighting.git
 \
  ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

git clone --depth 1 
https://github.com/marlonrichert/zsh-autocomplete.git
 \
  ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autocomplete

3.4 Cài Theme & Font

  • Cài Nerd Font theo distro (hoặc tải thủ công)
  • Đặt font trong terminal emulator bạn dùng (GNOME Terminal, Konsole, Alacritty, ...)
  • Cài theme powerlevel10k:
git clone --depth=1 
https://github.com/romkatv/powerlevel10k.git
 \
  ${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/themes/powerlevel10k

4) Chỉnh sửa file .zshrc

Mở file:

nano ~/.zshrc

4.1 Bật theme

Tìm dòng:

ZSH_THEME="robbyrussell"

Đổi thành:

ZSH_THEME="powerlevel10k/powerlevel10k"

4.2 Bật plugins

Tìm dòng plugins=(...) và cập nhật thành ví dụ:

plugins=(
	git
	zsh-autocomplete
	zsh-syntax-highlighting
)

⚠️ Thứ tự plugin quan trọng:

  • zsh-autocomplete nên được load trước zsh-syntax-highlighting.

  • zsh-syntax-highlighting thường nên đặt cuối danh sách plugins để highlight đúng.

Lưu file rồi thoát:

  • Ctrl + O → Enter
  • Ctrl + X

5) Áp dụng thay đổi (gọi source để hoàn tất)

source ~/.zshrc

Nếu đang dùng powerlevel10k lần đầu, có thể nó sẽ tự mở phần cấu hình. Nếu chưa thấy, chạy:

p10k configure

6) Troubleshooting nhanh

  • Không đổi được shell mặc định sau chsh****: đóng terminal, mở lại hoặc đăng xuất/đăng nhập.
  • Autocomplete không hoạt động: đảm bảo đã bật plugin zsh-autocomplete trong plugins=(...) và đã source ~/.zshrc.
  • Ký tự icon bị lỗi (ô vuông): thường do font chưa phải Nerd Font. Hãy cài và chọn lại font trong terminal.