ls.fish: Use gdircolors if available

See #5278.
This commit is contained in:
Fabian Homborg 2018-10-24 19:27:51 +02:00
parent afc82ff23e
commit b427cd1823

View file

@ -12,7 +12,15 @@ if command ls --version >/dev/null 2>/dev/null
end
if not set -q LS_COLORS
if command -sq dircolors
set -l dircolors
for d in gdircolors dircolors
if command -sq $d
set dircolors $d
break
end
end
if set -q dircolors[1]
set -l colorfile
for file in ~/.dir_colors ~/.dircolors /etc/DIR_COLORS
if test -f $file
@ -22,7 +30,7 @@ if command ls --version >/dev/null 2>/dev/null
end
# 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]
set -gx LS_COLORS ($dircolors -c $colorfile | string split ' ')[3]
# 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]