Put all the ls logic into the function

Doing it when sourcing isn't necessary or all that great.

Just make it an actual normal function file.
This commit is contained in:
Fabian Homborg 2020-05-23 09:20:17 +02:00
parent 928e80ad6a
commit a40a35cc52

View File

@ -1,21 +1,25 @@
#
# Make ls use colors and show indicators if we are on a system that supports that feature and writing to stdout.
#
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.
#
# 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.
# Also test -F because we'll want to define this function even with an ls that can't do colors (like NetBSD).
for opt in --color=auto -G --color -F
if command ls $opt / >/dev/null 2>/dev/null
function ls --description "List contents of directory" -V opt
__fish_set_lscolors
isatty stdout
and set -a opt -F
command ls $opt $argv
# 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.
# 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
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
end
break
end
# Set the colors to the default via `dircolors` if none is given.
__fish_set_lscolors
isatty stdout
and set -a opt -F
command ls $__fish_ls_color_opt $argv
end