Skip to content

Instantly share code, notes, and snippets.

@kesor
Last active January 16, 2025 05:11
Show Gist options
  • Save kesor/6e094187c85f05c30fc923d6923c1073 to your computer and use it in GitHub Desktop.
Save kesor/6e094187c85f05c30fc923d6923c1073 to your computer and use it in GitHub Desktop.
Wrapper around `eza` to make it have `ls`-like arguments, especially `-t`
#!/bin/bash
# CHANGE THIS
ACTUAL_EZA=/usr/local/bin/_eza
display_time="modified"
sort_time=""
args=()
while [ "$#" -gt 0 ]; do
arg="$1"
shift
case "$arg" in
--)
args+=("$arg")
break;
;;
--directory)
args+=("--list-dirs")
;; # Replace --directory with --list-dirs
--numeric-uid-gid)
args+=("--numeric")
;; # Replace --numeric-uid-gid with --numeric
--block-size | --author | --escape | --dired | --full-time | --kibibytes | --literal | --quoting-style | --size | --time-style | --width)
if [ "$#" -gt 0 ] && [ "${1#-}" = "$1" ]; then
shift
fi
;;
--time=*)
case "${arg#--time=}" in
atime|access|use)
display_time="accessed"
;;
ctime|status)
display_time="changed"
;;
birth|creation)
display_time="created"
;;
esac
;;
--sort=time)
sort_time="$display_time"
;;
--sort | --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
;;
--*)
args+=("$arg")
;;
-*)
shortopts="${arg#-}"
while [ -n "$shortopts" ]; do
char="${shortopts:0:1}"
shortopts="${shortopts:1}"
case "$char" in
L)
args+=("-X")
;; # Suppress -L
r)
args+=("--reverse")
;; # Suppress -r
S)
args+=("--sort=size")
;; # Supress -S
s)
;; # Supress -s (no equivalent in eza)
c)
display_time="changed"
;; # Supress -c
u)
display_time="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
t)
sort_time="old"
if [ "${shortopts:0:1}" = "c" ]; then
shortopts="${shortopts:1}"
display_time="created"
sort_time="created"
fi
;; # Suppress -t
*)
args+=("-${char}")
;;
esac
done
;;
*)
args+=("$arg")
;;
esac
done
args+=("--$display_time")
if [ -n "$sort_time" ]; then
args+=("--sort=$sort_time")
fi
args+=("$@")
# Execute eza with the processed arguments
exec "${ACTUAL_EZA}" "${args[@]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment