mauvehed's dotfiles for personal and work environments

Enhanced Command-Line Interface (CLI) Usage#

This document details configurations and tools aimed at creating a powerful, consistent, and user-friendly command-line interface (CLI) experience, primarily within a Zsh environment managed by chezmoi.

Overview#

A productive CLI environment goes beyond just the shell and prompt. It involves using enhanced versions of standard utilities, organizing shell configurations logically, and leveraging tools that streamline common tasks.

Striving for Consistency (GNU Coreutils on macOS)#

To achieve a more GNU/Linux-like CLI experience on macOS, GNU core utilities are often installed. These provide versions of common commands (ls, cp, mv, date, cat, etc.) with features and options consistent with their Linux counterparts.

  • Installation (macOS with Homebrew):
    brew install coreutils findutils gnu-tar gnu-sed gawk gnutls gnu-indent gnu-getopt grep
    
    (You might have a more specific list in your Brewfile.)
  • Usage: These GNU versions are typically prefixed with g (e.g., gls, gcat, gdate) to avoid conflicts with the native macOS utilities.
  • PATH Configuration: To use these GNU versions by their standard names (e.g., ls instead of gls), you would add their directory (e.g., $(brew --prefix coreutils)/libexec/gnubin) to the beginning of your $PATH.
    • This is often handled in a dedicated .path file or directly in your .zshrc / .zshenv, managed by chezmoi.

Shell Configuration Files#

To keep the main shell configuration file (e.g., ~/.zshrc) clean and organized, specific aspects of the shell setup are often broken out into separate files, sourced by the main config. These are managed by chezmoi.

  • ~/.path (or similar): Manages the $PATH environment variable. It defines the order in which directories are searched for executables. Example content:

    # Example .path structure
    export PATH="$HOME/.local/bin:$PATH"
    export PATH="$(brew --prefix)/bin:$(brew --prefix)/sbin:$PATH" # Homebrew
    # Add GNU coreutils if preferred
    # export PATH="$(brew --prefix coreutils)/libexec/gnubin:$PATH"
    
  • ~/.exports (or similar): Sets other essential environment variables (e.g., EDITOR, LANG, PAGER, custom variables for tools).

    # Example .exports
    export EDITOR='vim'
    export LANG='en_US.UTF-8'
    export PAGER='less'
    
  • ~/.functions (or similar): Defines custom shell functions to automate common tasks or create complex commands.

    # Example function in .functions
    # mkcd() {
    #   mkdir -p "$1" && cd "$1"
    # }
    
  • ~/.aliases (or similar): Contains command aliases for frequently used commands or commands with common options.

    # Example .aliases
    # alias ll='ls -alhF'
    # alias update='sudo apt update && sudo apt upgrade -y' # Linux example
    # alias brewup='brew update && brew upgrade && brew cleanup' # macOS example
    

These files are typically sourced from ~/.zshrc in a specific order.

Essential CLI Enhancement Tools#

These tools replace or augment standard CLI utilities for a better experience. They are usually installed via package managers (Homebrew, apt, etc.) and managed by chezmoi.

  • exa or lsd: Modern replacements for ls with more colors, icons, and features.
  • bat: A cat clone with syntax highlighting and Git integration.
  • fd: A simple, fast, and user-friendly alternative to find.
  • ripgrep (rg): A line-oriented search tool that recursively searches the current directory for a regex pattern (very fast alternative to grep).
  • fzf: A command-line fuzzy finder for history, files, processes, etc. Often integrated with shell keybindings (Ctrl+R, Ctrl+T).
  • zoxide: A smarter cd command that learns your habits.
  • jq: A lightweight and flexible command-line JSON processor.
  • yq: A command-line YAML, JSON, and XML processor (similar to jq but for more formats).
  • tldr: Collaborative cheatsheets for console commands. Provides simplified man pages.
  • navi or cheat: Interactive command-line cheatsheet tools.
  • procs: A modern replacement for ps written in Rust.
  • httpie or curlie: User-friendly CLI HTTP clients, alternatives to curl.

General Tips#

  • Keybindings: Customize Zsh keybindings (often in .zshrc or a dedicated file) for frequently used actions or fzf integrations.
  • Dotfiles Management: Use chezmoi edit <filename> to easily edit any of these configuration files.

Resources#

This setup aims to make your command-line interactions more efficient and enjoyable. Explore the tools and customize them to fit your workflow.