2020-07-12 19:17:43 +00:00
|
|
|
function __fish_set_lscolors --description 'Set $LS_COLORS if possible'
|
|
|
|
if ! set -qx LS_COLORS && set -l cmd (command -s {g,}dircolors)[1]
|
|
|
|
set -l colorfile
|
|
|
|
for file in ~/.dir_colors ~/.dircolors /etc/DIR_COLORS
|
|
|
|
if test -f $file
|
|
|
|
set colorfile $file
|
|
|
|
break
|
|
|
|
end
|
|
|
|
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 ($cmd -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]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-23 07:20:17 +00: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 13:02:03 +00:00
|
|
|
|
2020-05-23 07:20:17 +00: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-01 17:46:13 +00:00
|
|
|
# OpenBSD requires the separate colorls program for color support.
|
2020-05-23 07:20:17 +00: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 07:52:57 +00: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
|
|
|
|
set -g __fish_ls_color_opt -GF
|
|
|
|
set -g __fish_ls_command colorls
|
|
|
|
else
|
|
|
|
for opt in --color=auto -G --color -F
|
|
|
|
if command ls $opt / >/dev/null 2>/dev/null
|
|
|
|
set -g __fish_ls_color_opt $opt
|
|
|
|
break
|
|
|
|
end
|
2020-05-23 07:20:17 +00:00
|
|
|
end
|
2019-01-21 14:18:17 +00:00
|
|
|
end
|
2017-09-26 13:55:28 +00:00
|
|
|
end
|
2020-05-23 07:20:17 +00:00
|
|
|
|
|
|
|
# Set the colors to the default via `dircolors` if none is given.
|
|
|
|
__fish_set_lscolors
|
|
|
|
|
|
|
|
isatty stdout
|
|
|
|
and set -a opt -F
|
2021-06-01 17:46:13 +00:00
|
|
|
|
2021-06-03 07:52:57 +00:00
|
|
|
command $__fish_ls_command $__fish_ls_color_opt $argv
|
2006-02-08 09:20:05 +00:00
|
|
|
end
|