2020-05-23 15:20:17 +08:00
|
|
|
function ls --description "List contents of directory"
|
|
|
|
# Make ls use colors and show indicators if we are on a system that supports that feature and writing to stdout.
|
|
|
|
#
|
2006-02-20 21:02:03 +08:00
|
|
|
|
2020-05-23 15:20:17 +08:00
|
|
|
# BSD, macOS and others support colors with ls -G.
|
|
|
|
# GNU ls and FreeBSD ls takes --color=auto. Order of this test is important because ls also takes -G but it has a different meaning.
|
|
|
|
# Solaris 11's ls command takes a --color flag.
|
2021-06-02 01:46:13 +08:00
|
|
|
# OpenBSD requires the separate colorls program for color support.
|
2020-05-23 15:20:17 +08:00
|
|
|
# Also test -F because we'll want to define this function even with an ls that can't do colors (like NetBSD).
|
|
|
|
if not set -q __fish_ls_color_opt
|
|
|
|
set -g __fish_ls_color_opt
|
2021-06-03 15:52:57 +08:00
|
|
|
set -g __fish_ls_command ls
|
|
|
|
# OpenBSD ships a command called "colorls" that takes "-G" and "-F",
|
|
|
|
# but there's also a ruby implementation that doesn't understand "-F".
|
|
|
|
# Since that one's quite different, don't use it.
|
|
|
|
if command -sq colorls
|
|
|
|
and command colorls -GF >/dev/null 2>/dev/null
|
2023-11-02 19:50:02 +08:00
|
|
|
set -g __fish_ls_color_opt -G
|
2021-06-03 15:52:57 +08:00
|
|
|
set -g __fish_ls_command colorls
|
|
|
|
else
|
2023-11-02 19:50:02 +08:00
|
|
|
for opt in --color=auto -G --color
|
2021-06-03 15:52:57 +08:00
|
|
|
if command ls $opt / >/dev/null 2>/dev/null
|
|
|
|
set -g __fish_ls_color_opt $opt
|
|
|
|
break
|
|
|
|
end
|
2020-05-23 15:20:17 +08:00
|
|
|
end
|
2019-01-21 22:18:17 +08:00
|
|
|
end
|
2017-09-26 21:55:28 +08:00
|
|
|
end
|
2020-05-23 15:20:17 +08:00
|
|
|
|
2023-10-08 00:00:17 +08:00
|
|
|
set -l opt
|
2020-05-23 15:20:17 +08:00
|
|
|
isatty stdout
|
|
|
|
and set -a opt -F
|
2021-06-02 01:46:13 +08:00
|
|
|
|
2021-09-25 00:14:57 +08:00
|
|
|
# Terminal.app doesn't set $COLORTERM or $CLICOLOR,
|
|
|
|
# but the new FreeBSD ls requires either to be set,
|
|
|
|
# before it will enable color.
|
|
|
|
# See #8309.
|
|
|
|
# We don't set $COLORTERM because that should be set to
|
|
|
|
# "truecolor" or similar and we don't want to specify that here.
|
|
|
|
test "$TERM_PROGRAM" = Apple_Terminal
|
2021-09-25 00:17:49 +08:00
|
|
|
and set -lx CLICOLOR 1
|
2021-09-25 00:14:57 +08:00
|
|
|
|
2021-09-25 00:25:27 +08:00
|
|
|
command $__fish_ls_command $__fish_ls_color_opt $opt $argv
|
2006-02-08 17:20:05 +08:00
|
|
|
end
|