-
-
Save eggbean/74db77c4f6404dd1f975bd6f048b86f8 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
## Change following to '0' for output to be like ls and '1' for eza features | |
# Don't list implied . and .. by default with -a | |
dot=0 | |
# Show human readable file sizes by default | |
hru=1 | |
# Show file sizes in decimal (1KB=1000 bytes) as opposed to binary units (1KiB=1024 bytes) | |
meb=0 | |
# Don't show group column | |
fgp=0 | |
# Don't show hardlinks column | |
lnk=0 | |
# Show file git status automatically (can cause a slight delay in large repo trees) | |
git=1 | |
# Show icons | |
ico=0 | |
# Show column headers | |
hed=0 | |
# Group directories first in long listing by default | |
gpd=0 | |
# Colour always even when piping (can be disabled with -N switch when not wanted) | |
col=1 | |
help() { | |
cat << EOF | |
${0##*/} options: | |
-a all | |
-A almost all | |
-1 one file per line | |
-x list by lines, not columns | |
-l long listing format | |
-G display entries as a grid * | |
-k bytes | |
-h human readable file sizes | |
-F classify | |
-R recurse | |
-r reverse | |
-d don't list directory contents | |
-D directories only * | |
-P group directories first * | |
-I ignore [GLOBS] | |
-i show inodes | |
-o show octal permissions * | |
-N no colour * | |
-S sort by file size | |
-t sort by modified time | |
-u sort by accessed time | |
-c sort by created time * | |
-X sort by extension | |
-M time style [iso|long-iso|full-iso|relative] * | |
-T tree * | |
-L level [DEPTH] * | |
-s file system blocks | |
-g don't show/show file git status * | |
-O don't show/show icons * | |
-n ignore .gitignore files * | |
-b file sizes in binary/decimal (--si in ls) | |
-Z show each file's security context | |
-@ extended attributes and sizes * | |
* not used in ls | |
EOF | |
exit | |
} | |
[[ $* =~ --help ]] && help | |
eza_opts=() | |
while getopts ':aAbtucSI:rkhnsXL:M:PNg1lFGRdDioOTxZ@' arg; do | |
case $arg in | |
a) (( dot == 1 )) && eza_opts+=(-a) || eza_opts+=(-a -a) ;; | |
A) eza_opts+=(-a) ;; | |
t) eza_opts+=(-s modified); ((++rev)) ;; | |
u) eza_opts+=(-us accessed); ((++rev)) ;; | |
c) eza_opts+=(-Us created); ((++rev)) ;; | |
S) eza_opts+=(-s size); ((++rev)) ;; | |
I) eza_opts+=(--ignore-glob="${OPTARG}") ;; | |
r) ((++rev)) ;; | |
k) ((--hru)) ;; | |
h) ((++hru)) ;; | |
n) eza_opts+=(--git-ignore) ;; | |
s) eza_opts+=(-S) ;; | |
X) eza_opts+=(-s extension) ;; | |
L) eza_opts+=(--level="${OPTARG}") ;; | |
o) eza_opts+=(--octal-permissions) ;; | |
M) eza_opts+=(--time-style="${OPTARG}") ;; | |
P) ((++gpd)) ;; | |
N) ((++nco)) ;; | |
g) ((++git)) ;; | |
O) ((++ico)) ;; | |
b) ((--meb)) ;; | |
1|l|F|G|R|d|D|i|T|x|Z|@) eza_opts+=(-"$arg") ;; | |
:) printf "%s: -%s switch requires a value\n" "${0##*/}" "${OPTARG}" >&2; exit 1 | |
;; | |
*) printf "Error: %s\n --help for help\n" "${0##*/}" >&2; exit 1 | |
;; | |
esac | |
done | |
shift "$((OPTIND - 1))" | |
(( rev == 1 )) && eza_opts+=(-r) | |
(( fgp == 0 )) && eza_opts+=(-g) | |
(( lnk == 0 )) && eza_opts+=(-H) | |
(( hru <= 0 )) && eza_opts+=(-B) | |
(( hed == 1 )) && eza_opts+=(-h) | |
(( meb == 0 && hru > 0 )) && eza_opts+=(-b) | |
(( col == 1 )) && eza_opts+=(--color=always) || eza_opts+=(--color=auto) | |
(( nco == 1 )) && eza_opts+=(--color=never) | |
(( gpd >= 1 )) && eza_opts+=(--group-directories-first) | |
(( ico == 1 )) && eza_opts+=(--icons) | |
(( git == 1 )) && \ | |
[[ $(git -C ${*:-.} rev-parse --is-inside-work-tree) == true ]] 2>/dev/null && eza_opts+=(--git) | |
eza "${eza_opts[@]}" "$@" |
@eggbean I have another suggestion for this great wrapper: Change the bang to #!/usr/bin/env sh
and make the script POSIX compliant for the best portability. It seems there is not really much to it, except for porting the test expression [[
to [
, or did I miss something?
@martin-braun Quite a lot would have to be changed and it'll be a more complex and less readable as a result. No arrays
, no (( arithmetic expansion ))
, no =~
regex, $(process substitution)
would need to be changed to `backticks` and I think getopts
works differently. And then what would it be more portable for? It already can run on the old bash 3.2 that's installed on macOS. The zealots that I have met who only use sh
and nothing as extravagant as bash would never use something as ostentatious as eza
anyway😆 Thanks for the idea though.
I see. I only use that docker containers. apk add bash
only adds 3336 KiB, but I'd be surprised if minimalists who use it as a desktop OS would use eza.
@oxo-real Thanks, but I'm going to keep it disabled for now, as the colours used for this are far too contrasty in my opinion. They should be much more subtle and not be so distracting.