mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-29 06:13:20 +00:00
Extract setting $LS_COLORS to its own function
Makes it easier to override ls while keeping $LS_COLORS.
This commit is contained in:
parent
a9bfe7f164
commit
928e80ad6a
2 changed files with 19 additions and 18 deletions
18
share/functions/__fish_set_lscolors.fish
Normal file
18
share/functions/__fish_set_lscolors.fish
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
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
|
|
@ -9,30 +9,13 @@
|
||||||
|
|
||||||
for opt in --color=auto -G --color -F
|
for opt in --color=auto -G --color -F
|
||||||
if command ls $opt / >/dev/null 2>/dev/null
|
if command ls $opt / >/dev/null 2>/dev/null
|
||||||
|
|
||||||
function ls --description "List contents of directory" -V opt
|
function ls --description "List contents of directory" -V opt
|
||||||
|
__fish_set_lscolors
|
||||||
isatty stdout
|
isatty stdout
|
||||||
and set -a opt -F
|
and set -a opt -F
|
||||||
command ls $opt $argv
|
command ls $opt $argv
|
||||||
end
|
end
|
||||||
|
|
||||||
if [ $opt = --color=auto ] && ! 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
|
|
||||||
|
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue