lsd (LSDeluxe)

repository·main·Indexed 12 days ago

https://github.com/lsd-rs/lsd

A modern rewrite of the GNU ls command written in Rust, featuring colors, icons, tree-view, and advanced formatting options. Version 1.2.0 supports custom configuration via YAML files, Nerd Font integration for icons, and extensive CLI flags for sorting and display.

Tokens
10.7K
Snippets
43
Records
61
Agent score
97%

What's inside lsd

  1. Handle invalid UTF-8 characters in filenames

    main
    lsd attempts to display UTF-8 characters in filenames. If a filename contains invalid UTF-8, lsd will display the U+FFFD REPLACEMENT CHARACTER (�) to represent the invalid data.
  2. Install LSD

    main

    LSD can be installed via various package managers, from source using Cargo, or by downloading precompiled binaries.

    Prerequisites

    • Icons: To display icons, you must have a patched font like Nerd Fonts or Font Awesome installed and configured in your terminal.
    • Source Installation: Requires a working Rust toolchain.
    ### Installing from source
    With Rust's package manager cargo, you can install lsd via:
    ```sh
    cargo install lsd
  3. Enable Nerd Fonts in URxvt via .Xresources

    main

    To enable Nerd Fonts for the URxvt terminal emulator, add the following line to your .Xresources file, replacing Hack Nerd Font with your specific installed Nerd Font name.

    URxvt*font:    xft:Hack Nerd Font:style=Regular:size=11
  4. Install LSD via package manager

    main

    Use the command corresponding to your operating system or distribution:

    OS/DistroCommand
    Archlinuxpacman -S lsd
    Fedoradnf install lsd
    Gentoosudo emerge sys-apps/lsd
    macOSbrew install lsd or sudo port install lsd
    Nix (non NixOS)nix-env -iA nixpkgs.lsd
    NixOSAdd environment.systemPackages = [ pkgs.lsd ]; to system config
    FreeBSDpkg install lsd
    NetBSD/pkgsrcpkgin install lsd or cd /usr/pkgsrc/sysutils/lsd && make install
    OpenBSDpkg_add lsd
    Windowsscoop install lsd or winget install --id lsd-rs.lsd or choco install lsd
    Android (Termux)pkg install lsd
    Debian (sid/bookworm)apt install lsd
    Ubuntu 23.04+apt install lsd
    Soluseopkg it lsd
    Void Linuxsudo xbps-install lsd
    openSUSEsudo zypper install lsd
  5. Customize filetype colors using LS_COLORS

    main
    You can customize the colors used for specific file types in lsd by using the LS_COLORS environment variable. For help with creating complex themes, you can refer to external resources like trapd00r/LS_COLORS or sharkdp/vivid. Other colors (such as permissions, dates, and sizes) are managed via the lsd theme configuration.
  6. Use lsd to list directory contents

    main

    The lsd command provides an enhanced directory listing experience with colors and icons. You can list the current directory, a specific path, or use flags to modify the output format.

    Basic Usage

    • List current directory: lsd
    • List a specific directory: lsd /path/to/dir
    • List all entries (including hidden files): lsd -a or lsd --all
    • List in long format (extended metadata): lsd -l or lsd --long
    • Combine flags (e.g., long format including hidden files): lsd -la
    lsd -la
  7. Override icons in icons.yaml

    main

    You can customize icons using Nerd Font glyphs or Unicode emojis. lsd supports three types of icon overrides in icons.yaml:

    • name: Matches specific file or directory names (e.g., .cargo).
    • extension: Matches file extensions (e.g., rs).
    • filetype: Matches general categories (e.g., dir, executable, symlink-file).

    Custom icons are merged with the default set provided in the source.

    name:
      .trash: 
      .cargo: 
      .emacs.d: 
      a.out: 
    extension:
      go: 
      hs: 
      rs: 🦀
    filetype:
      dir: 📂
      file: 📄
      pipe: 📩
      socket: 󰆨
      executable: 
      symlink-dir: 
      symlink-file: 
      device-char: 
      device-block: 󰜫
      special: 
  8. Configure shell aliases for LSD

    main

    To use lsd instead of the standard ls command, add an alias to your shell configuration file (e.g., ~/.bashrc, ~/.zshrc).

    Basic replacement:

    alias ls='lsd'

    Useful productivity aliases:

    alias l='lsd -l'
    alias la='lsd -a'
    alias lla='lsd -la'
    alias lt='lsd --tree'
    alias ls='lsd'
    
    alias l='lsd -l'
    alias la='lsd -a'
    alias lla='lsd -la'
    alias lt='lsd --tree'
  9. Configure custom color schemes on Windows

    main
    To display custom color schemes on Windows, lsd relies on the LS_COLORS system environment variable. If your custom colors are not appearing, ensure that LS_COLORS is correctly set in your environment.
  10. Configure color usage and themes

    main

    LSD's color settings are determined by two main components: when (how to use colors) and theme (which color scheme to use). These settings can be configured via CLI flags, the configuration file, or environment variables.

    Color Usage (ColorOption)

    Controls when colors are displayed in the output:

    • always: Always use color.
    • auto: Use color automatically (default behavior).
    • never: Never use color.

    Note: Enabling --classic mode (via CLI or config) forces the color option to never.

    Theme Selection (ThemeOption)

    Controls the color scheme applied:

    • default: Use the built-in default theme.
    • custom: Use a custom YAML theme file.
    • no-color: Disable colors entirely.
    • <path>: Provide a path to a custom legacy theme file.

    Note: If classic mode is enabled in the configuration, the theme is automatically set to NoColor.

  11. Configure ignored glob patterns

    main

    You can prevent lsd from displaying certain files or directories by using glob patterns. These patterns can be specified via the CLI or in your configuration file.

    Precedence

    If patterns are defined in multiple places, lsd follows this order of precedence:

    1. CLI arguments (--ignore-glob)
    2. Configuration file (ignore-globs)
    3. Default value (an empty set, meaning nothing is ignored)

    Usage

    • CLI: Pass one or more patterns using the --ignore-glob flag.
    • Config: In your configuration file, provide an array of strings under the ignore-globs key.
    # CLI Example
    lsd --ignore-glob ".git" --ignore-glob "node_modules"
    
    # Configuration Example (YAML/JSON style)
    ignore-globs: [ ".git", "node_modules" ]
  12. How permission display is prioritized

    main

    The permission display format is determined by a hierarchy of settings:

    1. CLI Flags: If --classic is passed, the format is set to rwx. Otherwise, the value provided to --permission takes precedence.
    2. Configuration File: If the configuration file has classic = true, the format is set to rwx. Otherwise, the value of the permission key is used.
    3. Defaults:
      • On non-Windows systems: rwx is the default.
      • On Windows systems: attributes is the default.