I customized the directory and file colors for ls and cd + TAB. Here is my configuration.

My configuration

My system environment.

Ubuntu 10.10
zsh 4.3.10 (x86_64-unknown-linux-gnu)
oh-my-zsh // http://git://github.com/robbyrussell/oh-my-zsh.git

My .zshrc in $HOME.

// .zshrc
echo "Sourcing $0."
source $ZSH/oh-my-zsh.sh

A custom zsh script in ~/.oh-my-zsh/custom/completion.zsh

// completion.zsh
echo "Sourcing $0."
# Same completion colors when using cd as with ls.
zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}
zstyle ':completion:*:*:*:*:*' menu yes select

A custom zsh script in ~/.oh-my-zsh/custom/theme-and-appearance.zsh

// theme-and-appearance.zsh
echo "Sourcing $0."
export LS_COLORS='di=1;34:ln=35:so=32:pi=0;33:ex=32:bd=34;46:cd=34;43:su=0;41:sg=0;46:tw=1;34:ow=1;34:'

The problem description.

When I open the Terminal for the first time 3 files are sourced. Notice, that .zshrc does appear but not with its path nor file name.

Sourcing zsh.
Sourcing /home/john/.oh-my-zsh/custom/completion.zsh.
Sourcing /home/john/.oh-my-zsh/custom/theme-and-appearance.zsh.

Using the ls command the directory listing looks as expected. Though, when I use the cd command and TAB for autocompletion directory colors are not the same as with ls.

Then I source the configuration once again. Notice, this time .zshrc does appear with its full path and file name. I am not sure whether this contributes to the problem explained here.

$ . ~/.zshrc 
Sourcing /home/john/.zshrc.
Sourcing /home/john/.oh-my-zsh/custom/completion.zsh.
Sourcing /home/john/.oh-my-zsh/custom/theme-and-appearance.zsh.

Now both ls and cd + TAB use the same colors.


How do I have to change my configuration that the customization is loaded as soon as I open the Terminal application?

1 Answer 1


The problem is in the order the files are sourced. LS_COLORS must be defined before you run zstyle ':completion:*:default' list-colors ${(s.:.)LS_COLORS}.

You can fix this by renaming the files to something like 00theme-and-appearance.zsh and 01completion.zsh.

  • Damn. I did not see that. Thank you! Do you know a "nicer" solution besides renaming the files?
    – JJD
    Feb 5, 2012 at 19:10
  • @JJD If you want to keep it all in separate files then renaming them to start with numbers is a common practice to ensure files load in the correct order. Feb 7, 2012 at 20:05
  • I thought it could get difficult if dependencies are this way this time but for another case the are the other way around. Then renaming files would no longer help and I would need to extract definitions to another file. Is there something like a forward declaration like in programming languages?
    – JJD
    Feb 7, 2012 at 23:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .