ZSH Master Guide for NetBSD 10.1
Complete installation, configuration, and optimization guide
📑 Table of Contents
📦 ZSH Installation
1. Install via pkgin (Recommended)
Terminal Commands
# Update repositories
pkgin update
Install ZSH
pkgin install zsh
Verify installation
which zsh
zsh --version
2. Install via pkg_add (Alternative)
Terminal Commands
# Manual download and installation
pkg_add -v ftp://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/$(uname -m)/$(uname -r)/All/zsh-*
3. Set ZSH as Default Shell
Terminal Commands
# Check available shells
cat /etc/shells
Add ZSH to shells list (if not present)
sudo sh -c 'echo "/usr/pkg/bin/zsh" >> /etc/shells'
Change default shell
chsh -s /usr/pkg/bin/zsh
For root user (optional)
sudo chsh -s /usr/pkg/bin/zsh root
⚙️ Initial Configuration
1. Run Initial Setup
First Time Setup
# First execution - interactive configuration
zsh
Choose recommended options:
1) (1) Continue with configuration
2) (1) Configure again
3) (0) Exit and do nothing
text
2. Create Configuration Files
Create Configuration Structure
# Create directory for ZSH configurations
mkdir -p ~/.zsh
Create main configuration files
touch ~/.zshrc ~/.zshenv ~/.zprofile ~/.zshinitrc
🔧 Complete ~/.zshinitrc Configuration
~/.zshinitrc – Main Configuration File
#!/bin/zsh
==============================================================================
ZSHINITRC CONFIGURATION - NetBSD 10.1
==============================================================================
------------------------------------------------------------------------------
1. ESSENTIAL ENVIRONMENT VARIABLES
------------------------------------------------------------------------------
PATH - Order of precedence (most important first)
export PATH="$HOME/bin:/usr/local/bin:/usr/pkg/bin:/usr/X11R7/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Add NetBSD specific directories
export PATH="/usr/pkg/sbin:$PATH"
export PATH="/usr/pkg/gcc10/bin:$PATH" # If GCC installed
export PATH="/usr/pkg/qt6/bin:$PATH" # If Qt6 installed
Add user directories
export PATH="$HOME/.local/bin:$PATH"
export PATH="$HOME/.cargo/bin:$PATH" # For Rust
export PATH="$HOME/go/bin:$PATH" # For Go
------------------------------------------------------------------------------
2. SYSTEM VARIABLES
------------------------------------------------------------------------------
Terminal
export TERM="xterm-256color"
export COLORTERM="truecolor"
Default editor
export EDITOR="vim"
export VISUAL="vim"
Pager
export PAGER="less"
export LESS="-R"
Language
export LANG="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
History
export HISTSIZE=10000
export SAVEHIST=10000
export HISTFILE="$HOME/.zsh_history"
Timezone
export TZ="UTC"
------------------------------------------------------------------------------
3. NETBSD SPECIFIC VARIABLES
------------------------------------------------------------------------------
PKG_PATH for pkg_add
export PKG_PATH="ftp://ftp.netbsd.org/pub/pkgsrc/packages/NetBSD/$(uname -m)/$(uname -r)/All/"
For development
export CC="gcc"
export CXX="g++"
export LD_LIBRARY_PATH="/usr/pkg/lib:$LD_LIBRARY_PATH"
For Python (if installed via pkgin)
if [ -d "/usr/pkg/lib/python3.9" ]; then
export PYTHONPATH="/usr/pkg/lib/python3.9/site-packages:$PYTHONPATH"
fi
------------------------------------------------------------------------------
4. USEFUL ALIASES FOR NETBSD
------------------------------------------------------------------------------
Package management
alias pkgin-update='pkgin update && pkgin full-upgrade -y'
alias pkgin-search='pkgin search'
alias pkgin-install='sudo pkgin install'
alias pkgin-remove='sudo pkgin remove'
alias pkgin-list='pkgin list'
System
alias reboot='sudo shutdown -r now'
alias shutdown='sudo shutdown -p now'
alias netbsd-version='uname -a'
alias pkg-info='pkg_info'
Common shortcuts
alias ll='ls -laF'
alias la='ls -A'
alias l='ls -CF'
alias cls='clear'
alias h='history'
alias df='df -h'
alias du='du -h'
alias free='vmstat -s'
Safety
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
------------------------------------------------------------------------------
5. CUSTOM FUNCTIONS
------------------------------------------------------------------------------
Update complete system
function update-system() {
echo "🔄 Updating NetBSD..."
sudo pkgin update
sudo pkgin full-upgrade -y
echo "✅ System updated!"
}
Clean pkgin cache
function clean-pkgin() {
echo "🧹 Cleaning pkgin cache..."
sudo pkgin clean
echo "✅ Cache cleaned!"
}
System information
function sysinfo() {
echo "══════════════════════════════════════════════════════════════════════"
echo "🏔️ NETBSD SYSTEM INFORMATION"
echo "══════════════════════════════════════════════════════════════════════"
uname -a
echo "──────────────────────────────────────────────────────────────────────"
echo "Uptime: $(uptime)"
echo "──────────────────────────────────────────────────────────────────────"
echo "Memory:"
vmstat -s | grep -E "(pages free|pages active|pages inactive)"
echo "──────────────────────────────────────────────────────────────────────"
echo "Disk:"
df -h /
echo "══════════════════════════════════════════════════════════════════════"
}
------------------------------------------------------------------------------
6. PROMPT CONFIGURATION (OPTIONAL - SIMPLE)
------------------------------------------------------------------------------
Basic colored prompt
autoload -U colors && colors
PROMPT="%{$fg[green]%}%n@%m%{$reset_color%}:%{$fg[blue]%}%~%{$reset_color%}$ "
Right prompt with date/time
RPROMPT="%{$fg[yellow]%}[%*]%{$reset_color%}"
------------------------------------------------------------------------------
7. COMPLETION SYSTEM
------------------------------------------------------------------------------
Enable completion system
autoload -U compinit
compinit
Case-insensitive completion
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
Show selection menu
zstyle ':completion:*' menu select
------------------------------------------------------------------------------
8. ZSH OPTIONS
------------------------------------------------------------------------------
Auto-correction
setopt correct
setopt autocd
setopt nocaseglob
History
setopt appendhistory
setopt sharehistory
setopt incappendhistory
setopt histignoredups
setopt histignorespace
Other useful options
setopt extendedglob
setopt notify
setopt nobeep
------------------------------------------------------------------------------
9. PLUGINS (OPTIONAL - IF INSTALLED)
------------------------------------------------------------------------------
Load syntax highlighting
if [ -f "/usr/pkg/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" ]; then
source /usr/pkg/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
fi
Load autosuggestions
if [ -f "/usr/pkg/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh" ]; then
source /usr/pkg/share/zsh/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
fi
------------------------------------------------------------------------------
10. WELCOME MESSAGE
------------------------------------------------------------------------------
echo "╔══════════════════════════════════════════════════════════════════╗"
echo "║ ZSH CONFIGURED FOR NETBSD 10.1 ║"
echo "║ Shell: $(zsh --version | head -n1) ║"
echo "║ User: $USER ║"
echo "║ Hostname: $(hostname) ║"
echo "╚══════════════════════════════════════════════════════════════════╝"
📁 Recommended File Structure
Create Complete Structure
# Create complete structure
mkdir -p ~/.zsh/{plugins,completions,themes}
Main files
~/.zshrc # Main file (loads .zshinitrc)
~/.zshinitrc # Main configurations (PATH, aliases, etc.)
~/.zshenv # Environment variables (loaded first)
~/.zprofile # Executed on login (similar to .profile)
~/.zsh_history # Command history
Auxiliary files
~/.aliases # Additional aliases
~/.zsh_functions # Custom functions
~/.zsh_local # Local specific configurations
Minimal ~/.zshrc
~/.zshrc – Minimal Version
#!/bin/zsh
==============================================================================
MAIN ZSHRC FILE
==============================================================================
Load zshinitrc
if [ -f "$HOME/.zshinitrc" ]; then
source "$HOME/.zshinitrc"
else
echo "⚠️ Warning: ~/.zshinitrc not found!"
fi
Load local aliases
if [ -f "$HOME/.aliases" ]; then
source "$HOME/.aliases"
fi
Load local functions
if [ -f "$HOME/.zsh_functions" ]; then
source "$HOME/.zsh_functions"
fi
Machine-specific configuration
if [ -f "$HOME/.zsh_local" ]; then
source "$HOME/.zsh_local"
fi
🚀 Install Plugins (Optional)
1. Install Plugins via pkgin
Install Popular Plugins
# Check available plugins
pkgin search zsh-plugin
Install popular plugins
pkgin install zsh-syntax-highlighting
pkgin install zsh-autosuggestions
2. Configure Plugins in ~/.zshinitrc
Plugin Configuration
# Add before "WELCOME MESSAGE" section
Syntax Highlighting
if [ -f "/usr/pkg/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" ]; then
source /usr/pkg/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
ZSH_HIGHLIGHT_STYLES[path]='fg=cyan'
ZSH_HIGHLIGHT_STYLES[command]='fg=green'
fi
Autosuggestions
if [ -f "/usr/pkg/share/zsh-autosuggestions/zsh-autosuggestions.zsh" ]; then
source /usr/pkg/share/zsh-autosuggestions/zsh-autosuggestions.zsh
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE="fg=#666"
fi
🛡️ Troubleshooting Common Issues
1. PATH Issues
Diagnose and Fix PATH
# Diagnose PATH problems
echo "Current PATH:"
echo $PATH | tr ':' '\n' | nl
Fix duplicate PATH in .zshinitrc
export PATH=$(echo $PATH | awk -v RS=: '!($0 in a) {a[$0]; printf "%s%s", colon, $0; colon=":"}')
2. ZSH Won’t Start
Debug Startup Issues
# Test in safe mode
zsh -f
Check errors in .zshinitrc
zsh -x ~/.zshinitrc 2>&1 | grep -E "(error|Error|ERROR)"
3. Permission Problems
Fix Permissions
# Fix permissions
chmod 644 ~/.zshinitrc ~/.zshrc
chmod 700 ~/.zsh/
Verify ZSH is in shells list
grep zsh /etc/shells
💡 Final Tips for NetBSD 10.1
Performance
ZSH on NetBSD is stable, but avoid too many plugins if you have limited RAM.
Compatibility
Use pkgin to install plugins to ensure compatibility.
Backup
Always backup your configuration:
cp ~/.zshinitrc ~/.zshinitrc.backup
Updates
Keep ZSH updated:
pkgin update && pkgin upgrade zsh
🎯 Quick Setup (One-Liner)
Complete Setup Command
# Install and configure quickly
pkgin install zsh && chsh -s /usr/pkg/bin/zsh && curl -o ~/.zshinitrc https://example.com/zshinitrc-netbsd
Leave a Reply