2006-02-08 17:20:05 +08:00
|
|
|
#
|
2019-01-21 22:18:17 +08:00
|
|
|
# Make ls use colors and show indicators if we are on a system that supports that feature and writing to stdout.
|
2006-02-08 17:20:05 +08:00
|
|
|
#
|
2006-02-20 21:02:03 +08:00
|
|
|
|
2019-01-21 22:18: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.
|
2019-01-21 23:52:26 +08:00
|
|
|
# Also test -F because we'll want to define this function even with an ls that can't do colors (like NetBSD).
|
2019-01-21 22:18:17 +08:00
|
|
|
|
2019-01-21 23:52:26 +08:00
|
|
|
for opt in --color=auto -G --color -F
|
2019-01-21 22:18:17 +08:00
|
|
|
if command ls $opt / >/dev/null 2>/dev/null
|
|
|
|
|
|
|
|
function ls --description "List contents of directory" -V opt
|
|
|
|
isatty stdout
|
|
|
|
and set -a opt -F
|
|
|
|
command ls $opt $argv
|
|
|
|
end
|
2018-10-25 01:27:51 +08:00
|
|
|
|
2019-01-21 22:18:17 +08:00
|
|
|
if [ $opt = --color=auto ] &&! set -qx LS_COLORS && set -l cmd (command -s {g,}dircolors)[1]
|
2016-11-28 13:27:22 +08:00
|
|
|
set -l colorfile
|
|
|
|
for file in ~/.dir_colors ~/.dircolors /etc/DIR_COLORS
|
|
|
|
if test -f $file
|
|
|
|
set colorfile $file
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
2019-01-21 22:18:17 +08:00
|
|
|
# Here we rely on the legacy behavior of `dircolors -c` producing output
|
|
|
|
# suitable for csh in order to extract just the data we're interested in.
|
|
|
|
set -gx LS_COLORS ($cmd -c $colorfile | string split ' ')[3]
|
2016-12-08 05:55:31 +08:00
|
|
|
# The value should always be quoted but be conservative and check first.
|
|
|
|
if string match -qr '^([\'"]).*\1$' -- $LS_COLORS
|
|
|
|
set LS_COLORS (string match -r '^.(.*).$' $LS_COLORS)[2]
|
|
|
|
end
|
2016-11-28 13:27:22 +08:00
|
|
|
end
|
2019-01-21 22:18:17 +08:00
|
|
|
|
|
|
|
break
|
2017-09-26 21:55:28 +08:00
|
|
|
end
|
2006-02-08 17:20:05 +08:00
|
|
|
end
|