fix(init): set completion colors on theme load, not with `precmd`
This fixes an edge case where the user actually sets
zstyle ':completion:*' list-colors
in their zshrc, but the previous code used a precmd hook, which would
override the user changes. With this change our modifications will be
set in the init script, after the theme loads, so that later changes
can affect our defaults.
Note that this will not be run for users on plugin managers, as these
don't generally run our init script.
Diff
1diff --git a/lib/theme-and-appearance.zsh b/lib/theme-and-appearance.zsh
2index 985d3bc11b5d1273205f27d2156bc855de19bdf0..e245570e359881ed4d46bb196725e5f8af3ae013 100644
3--- a/lib/theme-and-appearance.zsh
4+++ b/lib/theme-and-appearance.zsh
5@@ -81,13 +81,3 @@ if [[ -z "$LS_COLORS" ]]; then
6 export LS_COLORS="di=34:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=37;41:sg=30;43:tw=30;42:ow=34;42:"
7 fi
8 fi
9-
10-# Take advantage of $LS_COLORS for completion as well.
11-function omz_set_completion_colors {
12- zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
13- add-zsh-hook -d precmd omz_set_completion_colors
14- unfunction omz_set_completion_colors
15-}
16-
17-autoload -Uz add-zsh-hook
18-add-zsh-hook precmd omz_set_completion_colors
19diff --git a/oh-my-zsh.sh b/oh-my-zsh.sh
20index 98bda8c8b81dd531c95aafc7352c1ea12bda9768..363cfca8baaefd2bb979db97ce6d06682ce89bd0 100644
21--- a/oh-my-zsh.sh
22+++ b/oh-my-zsh.sh
23@@ -189,3 +189,6 @@ if [[ -n "$ZSH_THEME" ]]; then
24 echo "[oh-my-zsh] theme '$ZSH_THEME' not found"
25 fi
26 fi
27+
28+# set completion colors to be the same as `ls`, after theme has been loaded
29+[[ -z "$LS_COLORS" ]] || zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"