Making ls -ltr Work with eza
Problem
Muscle memory uses ls -ltr but eza doesn’t support -t -r flags directly.
❯ ls -ltr
eza: Option --time (-t) has no "r" setting
Root Cause
- eza uses
--sort oldest/newestinstead of-t -r - oh-my-zsh sets
alias ls='ls -G'intheme-and-appearance.zsh - Alias overrides function definitions unless explicitly removed
Solution
Shell function that translates flags and removes oh-my-zsh alias.
# Remove oh-my-zsh's ls alias first
unalias ls 2>/dev/null
function ls() {
local args=()
local has_t=false
local has_r=false
# Parse user's flags
for arg in "$@"; do
if [[ "$arg" == -* ]] && [[ "$arg" != --* ]]; then
[[ "$arg" == *t* ]] && has_t=true
[[ "$arg" == *r* ]] && has_r=true
# Remove t and r, keep other flags like 'a'
local cleaned=$(echo "$arg" | sed 's/[tr]//g')
[[ "$cleaned" != "-" ]] && args+=("$cleaned")
else
args+=("$arg")
fi
done
# Build base args
if $has_t; then
# For time sorting: use all defaults
args=(-lh --group-directories-first --icons=auto "${args[@]}")
if $has_r; then
args+=(--sort oldest)
else
args+=(--sort newest)
fi
else
# For normal listing: use all defaults
args=(-lh --group-directories-first --icons=auto "${args[@]}")
fi
eza "${args[@]}"
}
Key Points
unalias ls 2>/dev/nullmust run before function definition- Translates
-ltr→-lh --group-directories-first --icons=auto --sort oldest - Translates
-lt→-lh --group-directories-first --icons=auto --sort newest - Preserves other flags like
-a(becomes-ltra)