2006-02-08 17:20:05 +08:00
|
|
|
#
|
2016-12-05 10:47:39 +08:00
|
|
|
# Make ls use colors if we are on a system that supports that feature and writing to stdout.
|
2006-02-08 17:20:05 +08:00
|
|
|
#
|
2016-12-05 10:47:39 +08:00
|
|
|
if command ls --version >/dev/null ^/dev/null
|
|
|
|
# This appears to be GNU ls.
|
2016-11-28 13:27:22 +08:00
|
|
|
function ls --description "List contents of directory"
|
|
|
|
set -l param --color=auto
|
|
|
|
if isatty 1
|
|
|
|
set param $param --indicator-style=classify
|
|
|
|
end
|
|
|
|
command ls $param $argv
|
|
|
|
end
|
2006-02-20 21:02:03 +08:00
|
|
|
|
2016-11-28 13:27:22 +08:00
|
|
|
if not set -q LS_COLORS
|
2017-02-14 00:30:38 +08:00
|
|
|
if command -sq dircolors
|
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
|
2016-12-05 10:47:39 +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 (dircolors -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
|
|
|
|
end
|
2016-12-05 10:47:39 +08:00
|
|
|
else if command ls -G / >/dev/null ^/dev/null
|
|
|
|
# It looks like BSD, OS X and a few more which support colors through the -G switch instead.
|
|
|
|
function ls --description "List contents of directory"
|
|
|
|
command ls -G $argv
|
2016-11-28 13:27:22 +08:00
|
|
|
end
|
2006-02-08 17:20:05 +08:00
|
|
|
end
|