1b799e9762067f912c0eb807cd5a55d8f122adfd

Author
Marc Cornellà <marc.cornella@live.com>
Committer
GitHub <noreply@github.com>
Date

Message

Check dircolors settings before using gls on darwin (#5570)

`gls` seems to be installed by default or on most macOS systems, but its
default color scheme sucks. This fix will make sure to only use it if it
has been customised prior to running OMZ.

Related: #5516, #5520.

Diff

 1diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh
 2index 467b770d66e93e727f8dcfe9a47ef6ef407d8c3c..122e3fecb61bba01b7ec071b7bccc11e259ff141 100644
 3--- a/lib/theme-and-appearance.zsh
 4+++ b/lib/theme-and-appearance.zsh
 5@@ -4,6 +4,8 @@ autoload -U colors && colors
 6 # Enable ls colors
 7 export LSCOLORS="Gxfxcxdxbxegedabagacad"
 8 
 9+# TODO organise this chaotic logic
10+
11 if [[ "$DISABLE_LS_COLORS" != "true" ]]; then
12   # Find the option for using colors in ls, depending on the version
13   if [[ "$OSTYPE" == netbsd* ]]; then
14@@ -18,7 +20,12 @@ if [[ "$DISABLE_LS_COLORS" != "true" ]]; then
15     gls --color -d . &>/dev/null && alias ls='gls --color=tty'
16     colorls -G -d . &>/dev/null && alias ls='colorls -G'
17   elif [[ "$OSTYPE" == darwin* ]]; then
18-    gls --color -d . &>/dev/null && alias ls='gls --color=tty' || alias ls='ls -G'
19+    # this is a good alias, it works by default just using $LSCOLORS
20+    alias ls='ls -G'
21+
22+    # only use coreutils ls if there is a dircolors customization present ($LS_COLORS or .dircolors file)
23+    # otherwise, gls will use the default color scheme which is ugly af
24+    [[ -n "$LS_COLORS" || -f "$HOME/.dircolors" ]] && gls --color -d . &>/dev/null && alias ls='gls --color=tty'
25   else
26     # For GNU ls, we use the default ls color theme. They can later be overwritten by themes.
27     if [[ -z "$LS_COLORS" ]]; then