Power-up macOS Zsh
TechWhen Apple switched to Zsh in macOS 10.15 Catalina, I relied on Armin Briegel's "Moving to Zsh" to guide me through the transition. This resource can be helpful for others making the switch.
As I adapted to Zsh, I noticed many users prefer Oh My Zsh for its useful features. However, I find it overkill for my needs, so I maintain my own config file for control and simplicity. I still reference Oh My Zsh plugins on GitHub for inspiration.
Below is my configuration file, with section explanations.
PATH
Adds your personal binaries (~/.local/bin) and common package manager locations (/usr/local/bin, /opt/homebrew/bin) to the front of the search path.
CMD HISTORY
Controls how command history is stored and shared.
-
HISTSIZE/SAVEHIST: Number of commands kept in memory and saved to file. -
HISTFILE: Location of your history file. -
HIST_IGNORE_DUPS: Avoids saving duplicate commands. -
HIST_IGNORE_SPACE: Commands starting with a space are not saved (useful for sensitive input). -
SHARE_HISTORY: Shares history across multiple terminal sessions. -
INC_APPEND_HISTORY: Writes commands to history immediately (not just on exit).
PROMPT
Sets the Zsh prompt to show your username in cyan, a colon, your current directory in yellow, and a $ at the end.
SYSTEM INFORMATION & DIAGNOSTICS
Quick commands for checking system status and hardware.
-
checkupdates/installupdates: Manage macOS updates viasoftwareupdate. -
sysinfo: Displays hardware details (CPU, RAM, model). -
meminfo: Shows memory usage stats. -
cpuinfo: Prints CPU model information.
SYSTEM CLEANUP
Manual maintenance function for performance and troubleshooting. Combines multiple cleanup tasks into one command.
- Flushes DNS cache (useful for networking issues).
- Clears user cache and log files to free space and remove stale data.
PRESENTER MODE
Useful for presentations or screen sharing. Toggles Finder visibility settings for a cleaner desktop.
-
hideicons/showicons: Hide or show desktop icons.
FILE AND STORAGE
Improves file management and safety.
- Safer defaults:
rm,cp,mvprompt before overwriting/deleting. -
ls,la: Enhanced directory listings with readable sizes and formatting. -
fileinfo: Displays file metadata. -
disks,freespace: Disk and storage inspection tools. -
targz(): Compresses files/folders into.tar.gz. -
rmdsstore(): Removes macOS.DS_Storefiles recursively.
NETWORKING
Useful commands for network info and troubleshooting.
-
resetnetwork: Restarts network interface. -
listening: Shows active listening ports. -
myip: Gets public IP address from ifconfig.me. -
localip: Gets local IP address. -
ports: Lists open network connections. -
ping: Sends 5 ICMP packets.
HOMEBREW
Manages packages installed via Homebrew.
-
brewup: Updates, upgrades, and cleans packages. -
brewlist: Lists installed packages. -
brewdeps: Shows dependency tree.
EXIFTOOL
Useful for privacy and file sanitization.
- Strips all metadata from files using ExifTool.
NMAP
Predefined scanning profiles using Nmap.
-
nmap_open_ports: Show only open ports. -
nmap_fast: Quick scan of common ports. -
nmap_full: Full aggressive scan of all ports. -
nmap_udp: UDP scan. -
nmap_vuln: Runs vulnerability detection scripts. -
nmap_versions: Detects service versions and OS.
# PATH
export PATH="$HOME/.local/bin:/usr/local/bin:/opt/homebrew/bin:$PATH" # CMD HISTORY
HISTSIZE=5000
SAVEHIST=5000
HISTFILE=~/.zsh_history
setopt HIST_IGNORE_DUPS
setopt HIST_IGNORE_SPACE
setopt SHARE_HISTORY
setopt INC_APPEND_HISTORY # PROMPT
PROMPT='%F{cyan}%n%f:%F{yellow}%~%f$' # SYSTEM INFORMATION & DIAGNOSTICS
alias checkupdates='softwareupdate -l'
alias installupdates='sudo softwareupdate -ia'
alias sysinfo='system_profiler SPHardwareDataType'
alias meminfo='vm_stat'
alias cpuinfo='sysctl -n machdep.cpu.brand_string' # SYSTEM CLEANUP
cleanup() {
echo "Flushing DNS cache..."
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
echo "Cleaning user caches and logs..."
rm -rf ~/Library/{Caches,Logs}/*
echo "Done."
} # PRESENTER MODE
alias hideicons="defaults write com.apple.finder CreateDesktop false && killall Finder"
alias showicons="defaults write com.apple.finder CreateDesktop true && killall Finder" # FILE AND STORAGE
alias ls='ls -GFh'
alias la='ls -A'
alias rm='rm -Iv'
alias cp='cp -i'
alias mv='mv -i'
alias fileinfo='mdls'
alias disks='diskutil list'
alias freespace='df -h'
targz() {
local name="${1%/}"
tar -czvf "${name}.tar.gz" "$name"
rmdsstore() {
find "${@:-.}" -type f -name .DS_Store -print -delete # NETWORKING
alias resetnetwork='sudo ifconfig en0 down && sudo ifconfig en0 up'
alias listening='lsof -iTCP -sTCP:LISTEN -n -P'
alias myip='curl -s ifconfig.me'
alias localip='ipconfig getifaddr en0'
alias ports='lsof -i -P -n'
alias ping='ping -c 5' # HOMEBREW
alias brewup='brew update && brew upgrade && brew cleanup'
alias brewlist='brew list'
alias brewdeps='brew deps --tree --installed' # EXIFTOOL
alias exiftool='exiftool -all= -overwrite_original' # NMAP
alias nmap_open_ports='nmap --open'
alias nmap_fast='nmap -F -T5 --version-light --top-ports 300'
alias nmap_full='sudo nmap -sS -T4 -A -p1-65535 -v'
alias nmap_udp='sudo nmap -sU -T4 -A -v'
alias nmap_vuln='nmap --script=vuln'
alias nmap_versions='sudo nmap -sV -O -T4 -Pn'