Last active
August 12, 2026 14:03
-
-
Save kesor/6e094187c85f05c30fc923d6923c1073 to your computer and use it in GitHub Desktop.
Wrapper around `eza` to make it have `ls`-like arguments, especially `-t`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # CHANGE THIS | |
| ACTUAL_EZA=/usr/local/bin/_eza | |
| args=() | |
| globs=() | |
| while [ "$#" -gt 0 ]; do | |
| arg="$1" | |
| shift | |
| case "$arg" in | |
| --) | |
| args+=("$arg") | |
| break; | |
| ;; | |
| --directory) | |
| args+=("--list-dirs") | |
| ;; # Replace --directory with --list-dirs | |
| --recursive) | |
| args+=("--recurse") | |
| ;; # Replace --recursive with --recurse | |
| --numeric-uid-gid) | |
| args+=("--numeric") | |
| ;; # Replace --numeric-uid-gid with --numeric | |
| --hide | --ignore) | |
| # ls --hide/--ignore take a glob pattern as the next token. | |
| # Collect globs separately; emit a single merged --ignore-glob | |
| # before exec (eza honors only the last --ignore-glob, so | |
| # multiple invocations must be combined into one). If no value | |
| # follows, pass the bare flag through so eza reports it like | |
| # ls would (ls itself requires a value here). | |
| if [ "$#" -gt 0 ] && [ "${1#-}" = "$1" ]; then | |
| globs+=("$1") | |
| shift | |
| else | |
| args+=("$arg") | |
| fi | |
| ;; | |
| --hide=* | --ignore=*) | |
| globs+=("${arg#*=}") | |
| ;; | |
| --block-size | --author | --escape | --dired | --full-time | --kibibytes | --literal | --quoting-style | --size | --time-style | --width) | |
| if [ "$#" -gt 0 ] && [ "${1#-}" = "$1" ]; then | |
| shift | |
| fi | |
| ;; | |
| --sort | --sort=* | --time | --time=* | --indicator-style | --indicator-style=* | --color | --color=* | --hyperlink | --hyperlink=*) | |
| if [ "${arg#*=}" != "$arg" ]; then | |
| args+=("$arg") | |
| else | |
| if [ "$#" -gt 0 ] && [ "${1#-}" = "$1" ]; then | |
| args+=("$arg" "$1") | |
| shift | |
| else | |
| args+=("$arg") | |
| fi | |
| fi | |
| ;; | |
| # ls-only long flags with no eza equivalent. Drop silently so | |
| # muscle-memory invocations don't error out on unknown args. | |
| --human-readable | --si | --file-type | --no-group | --quote-name | --hide-control-chars | --show-control-chars | --ignore-backups | --zero | --dereference-command-line | --dereference-command-line-symlink-to-dir) | |
| ;; # no-op: flag has no eza equivalent | |
| --format | --format=* | --tabsize | --tabsize=*) | |
| # These take an argument; consume it silently. | |
| if [ "${arg#*=}" = "$arg" ] && [ "$#" -gt 0 ] && [ "${1#-}" = "$1" ]; then | |
| shift | |
| fi | |
| ;; # no-op: flag has no eza equivalent | |
| --classify) | |
| # eza 0.23.5+ made WHEN mandatory. Bare --classify would | |
| # consume the next path arg as WHEN, erroring. Pin to always. | |
| args+=("--classify=always") | |
| ;; | |
| --*) | |
| args+=("$arg") | |
| ;; | |
| -*) | |
| arg="${arg#-}" | |
| while [ -n "$arg" ]; do | |
| char="${arg%"${arg#?}"}" | |
| case "$char" in | |
| t) | |
| args+=("--sort=old") # ls default sorting is "old" not "modified" | |
| ;; # Suppress -t | |
| r) | |
| args+=("--reverse") | |
| ;; # Suppress -r | |
| S) | |
| args+=("--sort=size") | |
| ;; # Supress -S | |
| s) | |
| ;; # Supress -s (no equivalent in eza) | |
| c) | |
| args+=("--sort=changed") | |
| ;; # Supress -c | |
| u) | |
| args+=("--sort=accessed") | |
| ;; # Supress -u | |
| 1) | |
| args+=("--oneline") | |
| ;; # Supress -1 | |
| g) | |
| args+=("--group") | |
| ;; # Supress -g | |
| d) | |
| args+=("--list-dirs") | |
| ;; # Supress -d | |
| p) | |
| args+=("--indicator-style=slash") | |
| ;; # Supress -p | |
| F) | |
| # eza 0.23.5+ made --classify's WHEN argument | |
| # mandatory. Bare -F would consume the next | |
| # path arg as WHEN, erroring. Pin to always. | |
| args+=("--classify=always") | |
| ;; # Suppress -F | |
| *) | |
| args+=("-${char}") | |
| ;; | |
| esac | |
| arg="${arg#?}" | |
| done | |
| ;; | |
| *) | |
| args+=("$arg") | |
| ;; | |
| esac | |
| done | |
| args+=("$@") | |
| # Emit any collected globs as a single merged --ignore-glob=pat1|pat2|... | |
| if [ "${#globs[@]}" -gt 0 ]; then | |
| joined="" | |
| for g in "${globs[@]}"; do | |
| if [ -n "$joined" ]; then | |
| joined="$joined|$g" | |
| else | |
| joined="$g" | |
| fi | |
| done | |
| args=("--ignore-glob=$joined" "${args[@]}") | |
| fi | |
| exec "${ACTUAL_EZA}" "${args[@]}" |
Author
Nice wrapper, thank you.
One arg I found missing:
--recursive)
args+=("--recurse")
;;
Author
@darioseidl thank you! I updated the script with this, as well as other fixes that accumulated since I first wrote it a year ago.
@kesor thanks!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Related issues: