Prezto Zsh Configuration Framework

repository·master·Indexed 12 days ago

https://github.com/sorin-ionescu/prezto

An 'instantly awesome' Zsh configuration framework providing a modular system for shell enhancement. Includes modules for tmux session management, autosuggestions, command-not-found suggestions, completion, directory navigation, and specialized aliases for Docker, DNF, and Dpkg.

Tokens
26.9K
Snippets
92
Records
139
Agent score
97%

What's inside Prezto

  1. Use the Command-Not-Found module

    master

    The command-not-found module improves your shell experience by searching your package manager for a package that provides a command when you attempt to run a command that is not installed locally. It then suggests the correct installation command.

    Platform Support

    • Debian and Arch Linux: Uses the standard command-not-found tool.
    • macOS: Uses the Homebrew command-not-found clone. Prezto automatically loads this tool without requiring you to manually source handler.sh in your .zshrc.

    Homebrew Notes

    If you are on macOS, note that prior to Homebrew version 4.6.12, you might have needed to tap the homebrew-command-not-found repository. While Prezto will attempt to use this as a fallback if the handler isn't found in Homebrew core, the repository is deprecated. It is recommended to upgrade Homebrew to avoid warnings and untap the deprecated repository.

  2. Ruby version manager detection

    master

    The Ruby module automatically detects and loads various Ruby version managers:

    • rbenv: Loaded automatically if installed to $RBENV_ROOT, ~/.rbenv, or if the rbenv command is available in your $PATH. It is recommended for users who want to avoid shell conflicts.
    • rvm: Loaded automatically. Note: Because RVM is loaded into the shell and can override commands, you should load this module as late as possible in your configuration to prevent $PATH complaints.
    • chruby: A simpler alternative that supports auto-switching via zstyle configuration.

    If no version manager is detected, local gems are installed in ~/.gem.

  3. Configure the Utility module loading order

    master

    The utility module defines general aliases and functions. To ensure completion definitions are loaded correctly, you must follow a specific loading order in your configuration:

    1. gnu-utility (optional, if using non-GNU systems with incompatible arguments)
    2. utility
    3. completion

    If you are on a non-GNU system and encounter incompatible arguments, load gnu-utility before utility.

  4. Configure the loading order for syntax-highlighting

    master

    The syntax-highlighting module has strict loading order requirements to function correctly with other modules. To avoid conflicts, ensure it is loaded in the following relative order:

    1. syntax-highlighting (Must be first)
    2. history-substring-search
    3. autosuggestions
    4. prompt (Must be last)

    Specifically, syntax-highlighting must be loaded before prompt, history-substring-search, and autosuggestions.

  5. Configure Node.js module loading for nodenv and nvm

    master

    The module automatically detects and loads Node version managers if they are installed in standard locations:

    • nodenv: Detected if installed in $NODENV_ROOT, $XDG_CONFIG_HOME/nodenv, ~/.nodenv, or if nodenv is available on your PATH.
    • nvm: Detected if installed in $NVM_DIR, $XDG_CONFIG_HOME/nvm, ~/.nvm, or installed via Homebrew.
  6. Understand the Zsh and Prezto configuration file lifecycle

    master

    Zsh and Prezto use a specific sequence of configuration files that are read in a deterministic order. Understanding this order is crucial for knowing where to place environment variables, aliases, or Prezto-specific settings.

    Configuration File Order

    1. /etc/zshenv (System-wide)
    2. ${ZDOTDIR:-$HOME}/.zshenv (User-local)
    3. /etc/zprofile (System-wide)
    4. ${ZDOTDIR:-$HOME}/.zprofile (User-local)
    5. /etc/zshrc (System-wide)
    6. ${ZDOTDIR:-$HOME}/.zshrc (User-local)
    7. ${ZDOTDIR:-$HOME}/.zpreztorc (Prezto configuration)
    8. /etc/zlogin (System-wide)
    9. ${ZDOTDIR:-$HOME}/.zlogin (User-local)
    10. ${ZDOTDIR:-$HOME}/.zlogout (User-local)
    11. /etc/zlogout (System-wide)

    File Locations

    • System-wide files: Usually located in /etc.
    • User-local files: Prefixed with a dot (e.g., .zshrc). Zsh looks for these in the directory specified by the $ZDOTDIR environment variable. If $ZDOTDIR is not set, it defaults to your home directory ($HOME).
  7. Use the Spectrum module for colors and effects

    master

    The spectrum module provides easy access to 256 colors and text effects in Zsh. It exposes three primary variable arrays to manage terminal styling:

    • $BG: Background colors.
    • $FG: Foreground (text) colors.
    • $FX: Text effects (e.g., bold, underline).

    Before using these, ensure your terminal supports 256 colors by running tput colors in your terminal. Supported color identifiers include integers 0 to 255, as well as named colors like black, red, green, yellow, blue, magenta, cyan, and white.

  8. Use the GNU Utility module for interactive GNU tools on BSD

    master

    The gnu-utility module provides interactive access to GNU utilities on non-GNU systems (like BSD). Instead of replacing system utilities in your $PATH (which can break scripts), this module wraps GNU utilities in functions that allow you to use them without a prefix during interactive sessions.

    Important Loading Order: You must load this module before the utility module. This ensures that the GNU utilities enabled by this module are available for configuration within the utility module.

  9. How to use the Completion module

    master

    The Completion module configures <kbd>TAB</kbd> completion and integrates additional completions from the zsh-completions project.

    Important Loading Order: This module must be loaded late, specifically after the utility module and any other modules that provide completion definitions.