Terminal does not source .zshrc with custom colors for ls and cd command

7,151

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.

Share:
7,151

Related videos on Youtube

JJD
Author by

JJD

Android, Kotlin, Java, Git, Python, Ruby, Ruby on Rails, JavaScript, MacOS, Ubuntu #SOreadytohelp http://stackoverflow.com/10m

Updated on September 18, 2022

Comments

  • JJD
    JJD over 1 year

    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
    Terminal
    

    My .zshrc in $HOME.

    // .zshrc
    echo "Sourcing $0."
    ZSH=$HOME/.oh-my-zsh
    ZSH_THEME="josh"
    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.


    Question

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

  • JJD
    JJD about 12 years
    Damn. I did not see that. Thank you! Do you know a "nicer" solution besides renaming the files?
  • Arrowmaster
    Arrowmaster about 12 years
    @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.
  • JJD
    JJD about 12 years
    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?