Lewati ke konten
Kembali ke Blog

Cara Setup ZSH dan Oh-My-Zsh di Ubuntu untuk Terminal yang Cantik

· · 7 menit baca

ZSH (Z Shell) adalah shell yang powerful dengan fitur auto-completion, syntax highlighting, dan plugin system. Dengan Oh-My-Zsh framework, Anda dapat mengkonversi terminal standar menjadi interface yang cantik dan sangat produktif.

1. Instalasi ZSH di Ubuntu

Install ZSH Package

# Update package list
sudo apt update

Install zsh

sudo apt install zsh -y

Verifikasi instalasi

zsh --version

Ganti default shell ke zsh

chsh -s $(which zsh)

Verifikasi shell saat ini

echo $SHELL

Note: Setelah mengubah default shell, logout dan login kembali atau restart terminal.

Konfigurasi Awal ZSH

Saat pertama kali menjalankan ZSH, Anda akan ditanya konfigurasi:

This is the Z Shell configuration function for new users,
You are seeing this message because you have no zsh dotfiles...

(0) Exit and create ~/.zshrc yourself (1) Configure settings for history, completion, etc. (2) Populate your ~/.zshrc with the configuration recommended by the system administrator

Please select one option: 2

Pilih option 2 untuk konfigurasi default yang direkomendasikan.

2. Instalasi Oh-My-Zsh Framework

Oh-My-Zsh adalah framework open-source yang mengelola konfigurasi ZSH dengan ribuan plugin dan tema.

Install Oh-My-Zsh via curl

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

Install via wget (alternatif)

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

Install via Git (untuk kontrol lebih)

# Backup existing .zshrc
mv ~/.zshrc ~/.zshrc.backup

Clone oh-my-zsh

export ZSH="$HOME/.oh-my-zsh" git clone https://github.com/ohmyzsh/ohmyzsh.git "$ZSH"

Copy template config

cp "$ZSH/templates/zshrc.zsh-template" ~/.zshrc

3. Konfigurasi Tema Oh-My-Zsh

Oh-My-Zsh memiliki 140+ tema built-in yang dapat Anda pilih.

Tema Populer

Edit ~/.zshrc dan ubah baris ZSH_THEME:

# Tema default
ZSH_THEME="robbyrussell"

Tema Powerline (butuh font special)

ZSH_THEME="agnoster"

Tema minimalis

ZSH_THEME="minimal"

Tema dengan banyak informasi

ZSH_THEME="bira"

Tema vintage

ZSH_THEME="miloshadzic"

Tema dengan icon git

ZSH_THEME="ys"

Random theme setiap session

ZSH_THEME="random"

Install Powerline Fonts (untuk tema Agnoster)

# Clone powerline fonts
git clone https://github.com/powerline/fonts.git --depth=1

Install

cd fonts ./install.sh

Cleanup

cd .. rm -rf fonts

Set font di terminal emulator (Preferences > Profile > Text)

Pilih: Meslo LG S for Powerline, atau font lain dengan glyphs

Install Nerd Fonts (untuk icon yang lebih baik)

# Download dan install Nerd Font
mkdir -p ~/.local/share/fonts
cd ~/.local/share/fonts
curl -fLo "Hack Regular Nerd Font Complete.ttf" \
  https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/Hack/Regular/complete/Hack%20Regular%20Nerd%20Font%20Complete.ttf

Update font cache

fc-cache -fv

4. Plugin ZSH yang Wajib Install

Plugin Built-in Oh-My-Zsh

Edit ~/.zshrc dan tambahkan ke array plugins:

plugins=(
    git
    z
    extract
    sudo
    colored-man-pages
    command-not-found
    history
    history-substring-search
    web-search
    encode64
    copypath
    copyfile
    copybuffer
    dirhistory
    jsontools
    vscode
    docker
    kubectl
    npm
    node
    python
    pip
    golang
    ruby
    bundler
    rails
    gem
    composer
    laravel
    symfony
    wp-cli
    redis-cli
    zsh-autosuggestions
    zsh-syntax-highlighting
)

Install Plugin Eksternal

zsh-autosuggestions

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

zsh-syntax-highlighting

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

zsh-completions

git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions

fast-syntax-highlighting (alternatif yang lebih cepat)

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

5. Kustomisasi Lanjutan

Custom Alias

Tambahkan ke ~/.zshrc:

# Navigation
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."

List dengan berbagai format

alias ls="ls --color=auto" alias ll="ls -lah" alias la="ls -A" alias l="ls -CF"

Git shortcut

alias g="git" alias ga="git add" alias gc="git commit" alias gp="git push" alias gl="git pull" alias gs="git status" alias gd="git diff" alias gco="git checkout" alias gb="git branch"

Update system

alias update="sudo apt update && sudo apt upgrade -y" alias cleanup="sudo apt autoremove && sudo apt clean"

Quick edit

alias zshconfig="nano ~/.zshrc" alias ohmyzsh="nano ~/.oh-my-zsh"

Utility

alias cls="clear" alias mkdirp="mkdir -p" alias ports="netstat -tulanp" alias meminfo="free -h" alias cpuinfo="lscpu" alias diskinfo="df -h"

Custom Functions

# Create direktori dan masuk ke dalamnya
mkcd() {
    mkdir -p "$1" && cd "$1"
}

Extract berbagai archive formats

extract() { if [ -f "$1" ]; then case "$1" in .tar.bz2) tar xjf "$1" ;; .tar.gz) tar xzf "$1" ;; .bz2) bunzip2 "$1" ;; .rar) unrar x "$1" ;; .gz) gunzip "$1" ;; .tar) tar xf "$1" ;; .tbz2) tar xjf "$1" ;; .tgz) tar xzf "$1" ;; .zip) unzip "$1" ;; .Z) uncompress "$1";; .7z) 7z x "$1" ;; ) echo "'\$1' tidak dapat di-extract" ;; esac else echo "'\$1' bukan file yang valid" fi }

Backup file dengan timestamp

backup() { cp "$1" "$1.bak.$(date +%Y%m%d_%H%M%S)" }

Search history

histgrep() { history | grep "$1" }

Kill process by name

killp() { ps aux | grep "$1" | grep -v grep | awk '{print $2}' | xargs kill -9 }

Prompt Kustom dengan Informasi Git

# Prompt dengan user, host, path, dan git branch
PROMPT='%F{green}%n%f@%F{magenta}%m%f %F{blue}%2~%f %F{yellow}$(git_prompt_info)%f %# '

Git prompt format

ZSH_THEME_GIT_PROMPT_PREFIX="git:(" ZSH_THEME_GIT_PROMPT_SUFFIX=")" ZSH_THEME_GIT_PROMPT_DIRTY=" ✗" ZSH_THEME_GIT_PROMPT_CLEAN=" ✓"

6. Troubleshooting Umum

Icon Tidak Muncul dengan Benar

# Pastikan font sudah terinstall
fc-list | grep -i "powerline\|nerd"

Set font di terminal emulator

GNOME Terminal: Preferences > Profile > Text

Konsole: Settings > Edit Current Profile > Appearance

Test dengan print icon

echo $'\uE0B0 \uE0B1 \uE0B2'

ZSH Lambat atau Lag

# Disable auto-update untuk kecepatan
DISABLE_AUTO_UPDATE="true"

Cache completion

zstyle ':completion: ' use-cache on zstyle ':completion:' cache-path ~/.zsh/cache

Lazy load nvm (jika menggunakan)

lazy_load_nvm() { unset -f node nvm npm npx export NVM_DIR="$HOME/.nvm" [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" }

alias node='lazy_load_nvm; node' alias npm='lazy_load_nvm; npm' alias npx='lazy_load_nvm; npx'

Oh-My-Zsh Tidak Terload

# Verifikasi ZSH_CUSTOM
export ZSH="$HOME/.oh-my-zsh"
echo $ZSH

Check source line di .zshrc

grep "source.*oh-my-zsh.sh" ~/.zshrc

Fix permission

chmod 755 ~/.oh-my-zsh chmod 644 ~/.zshrc

Reload

source ~/.zshrc

Kesimpulan

ZSH dengan Oh-My-Zsh mengubah terminal menjadi tools yang powerful dan menyenangkan untuk digunakan. Dengan auto-suggestion, syntax highlighting, dan ratusan plugin, produktivitas Anda akan meningkat signifikan.

Keunggulan ZSH + Oh-My-Zsh:
– Auto-completion yang superior
– Syntax highlighting real-time
– Git integration otomatis
– 300+ plugin siap pakai
– 140+ tema untuk personalisasi
– Sharing history antar session
– Globbing dan wildcard yang powerful

Tips Maintenance:
– Update Oh-My-Zsh secara berkala: omz update
– Update plugin eksternal dengan git pull
– Backup .zshrc sebelum modifikasi besar
– Gunakan version control untuk dotfiles

Alternatif Framework:
Prezto: Fork Oh-My-Zsh yang lebih cepat
Zim: Framework modular yang ringan
Antigen: Plugin manager untuk ZSH
Zplug: Plugin manager dengan parallel install

Ditulis oleh

Hendra Wijaya

Tinggalkan Komentar

Email tidak akan ditampilkan.