# Zsh (Z Shell) Zsh (Z Shell) is a powerful Unix [[Shell]] that extends [[Bash]] with additional features. It became macOS's default shell in Catalina (2019), replacing Bash. Zsh combines the best features of Bash, ksh, and tcsh while adding its own innovations. Known for its interactive features and extensive customization options, Zsh has become popular among developers who want a more productive command line experience. ## Key Features - **Advanced tab completion**: Context-aware, with menu selection - **Spelling correction**: Suggests fixes for typos - **Path expansion**: `cd /u/lo/b` expands to `/usr/local/bin` - **Shared history**: History shared across terminal sessions - **Globbing**: Extended pattern matching (`**/*.js` for recursive) - **Prompt customization**: Highly configurable prompts with themes - **Plugin system**: Extensible through frameworks like Oh My Zsh ## Differences from Bash | Feature | Zsh | [[Bash]] | |---------|-----|------| | Array indexing | 1-based | 0-based | | Extended globbing | Built-in | Requires `shopt` | | Spelling correction | Built-in | Not available | | Right-side prompt | Supported | Not supported | | Floating point math | Built-in | Requires `bc` | ## Oh My Zsh See [[Oh My Zsh]]. ## Configuration Files - `~/.zshrc`: Main configuration file (equivalent to `.bashrc`) - `~/.zshenv`: Loaded for all shells (environment variables) - `~/.zprofile`: Loaded for login shells - `~/.zlogin`: Loaded after `.zprofile` for login shells - `~/.zlogout`: Loaded when login shell exits - `~/.zsh_history`: Command history ### Loading Order - User-specific - .zshenv (login, interactive, scripts, terminal app) - .zprofile (login, terminal app) - .zshrc (interactive, terminal app) - .zlogin (login, terminal app) - .zlogout (login, terminal app) ## Popular Plugins - **zsh-autosuggestions**: Fish-like command suggestions - **zsh-syntax-highlighting**: Real-time syntax coloring - **z**: Jump to frequently used directories - **git**: Git aliases and prompt integration - **fzf**: Fuzzy finder integration ## Useful Features ### Directory Stack ```zsh pushd /path # Push directory to stack popd # Pop and return to previous dirs # List directory stack ``` ### Named Directories ```zsh hash -d proj=~/Projects cd ~proj # Jump to ~/Projects ``` ### Suffix Aliases ```zsh alias -s md=code # Open .md files with VS Code alias -s json=jq # Pipe .json files through jq ``` ## References - https://www.zsh.org/ - https://ohmyz.sh/ - https://en.wikipedia.org/wiki/Z_shell ## Related - [[Shell]] - [[Bash]] - [[Git Bash]] - [[TMux]] - [[jq]] - [[Command Line Interface (CLI)]] - [[Terminal User Interface (TUI)]]