Changing directory color with zsh + Prezto
Asked Answered
G

4

11

I am using Prezto + zsh as my shell. I would like to change the color of directories when I ls my directory. For instance, here is what I currently have:

My crappy ls listing

Obviously, this is no fun, as I’m hardly able to read my directories because the blue is so dark. I’d like to change it to white or orange or something lighter.

This dark blue is specific only to directories. Files show up in a nice white text. Where and what settings must I find to change this?

Guzel answered 16/10, 2015 at 19:35 Comment(0)
T
2

The answer depends on your ls. BSD ls uses the environment variable LSCOLORS; coreutils ls uses LS_COLORS instead. See your man page.

The utility module of Prezto uses dircolors (if available) to customize the colors of coreutils ls, which also comes with coreutils. So if you have coreutils, then you can use dircolors to provide actually human-readable color definitions. Read the man page of dircolors for details. Prezto reads from $HOME/.dir_colors by default, otherwise it just use the default colors defined by dircolors. You can of course specify other locations by editing on top of Prezto.

For BSD ls, there's probably no utility comparable to dircolors, so one has to manually define LSCOLORS. See the ENVIRONMENT section of the man page on its format, which should be pretty clear. An example is LSCOLORS='exfxcxdxbxGxDxabagacad', used by Prezto by default. To have it take effect, put it in runcoms, after loading Prezto's utility module.

Taconite answered 17/10, 2015 at 21:37 Comment(8)
Do you mean that if I just specify dircolors at the bottom of my .zshrc file, I can change this color? And if so, what would that dircolors look like?Guzel
dircolors is a command. What's your OS? And do you have coreutils installed?Taconite
I'm on a MacBook with El Capitan. I don't see coreutils in /usr/libexec/ so I don't believe so.Guzel
Well, coreutils is a package... But if you don't know what it is, chances are you don't have it.Taconite
I would seriously recommend coreutils though. On OS X you can easily install coreutils with brew install coreutils (requires Homebrew, obviously), then putting coreutils' libexec before /usr/bin in your PATH. I don't want to get into religious conflicts, but after you use coreutils for a while, you'll find BSD utilities shipped with OS X like crippled cousins. Seriously.Taconite
Would it matter which file in runcoms? I was thinking zshrc but don't have much reasoning for that.Guzel
Read man zsh, STARTUP/SHUTDOWN FILES section. It clearly indicates which file is for what. Here you want ls to show colors only in an interactive shell, and it doesn't matter whether it's a login shell or not, so it should go into zshrc.Taconite
Let us continue this discussion in chat.Guzel
S
25

Update

I've seen this answer still getting attention, so here's an update. Instead of messing with individual colours as below, simply adjust the Minimum Contrast within Preferences ... -> Profiles -> Colors. I set mine to 60.

enter image description here

Original answer

The easier way to do this is to change the colour scheme of your terminal. For example if you are using iTerm2 on a Mac then:

  • Launch iTerm2
  • type CMD+i
  • In the "Colors" tab, change the setting for "Blue" (and potentially the "Bright" equivalient)
  • In the "General" tab, click "Copy Current Settings to Selected Profile"

If you want to revert back to the defaults you can always select a value from the "Color presets..." dropdown in the "Colors" tab.

Do the equivalent in your favourite terminal if you don't use iTerm2 on a Mac.

Stephine answered 14/6, 2016 at 21:40 Comment(0)
T
2

The answer depends on your ls. BSD ls uses the environment variable LSCOLORS; coreutils ls uses LS_COLORS instead. See your man page.

The utility module of Prezto uses dircolors (if available) to customize the colors of coreutils ls, which also comes with coreutils. So if you have coreutils, then you can use dircolors to provide actually human-readable color definitions. Read the man page of dircolors for details. Prezto reads from $HOME/.dir_colors by default, otherwise it just use the default colors defined by dircolors. You can of course specify other locations by editing on top of Prezto.

For BSD ls, there's probably no utility comparable to dircolors, so one has to manually define LSCOLORS. See the ENVIRONMENT section of the man page on its format, which should be pretty clear. An example is LSCOLORS='exfxcxdxbxGxDxabagacad', used by Prezto by default. To have it take effect, put it in runcoms, after loading Prezto's utility module.

Taconite answered 17/10, 2015 at 21:37 Comment(8)
Do you mean that if I just specify dircolors at the bottom of my .zshrc file, I can change this color? And if so, what would that dircolors look like?Guzel
dircolors is a command. What's your OS? And do you have coreutils installed?Taconite
I'm on a MacBook with El Capitan. I don't see coreutils in /usr/libexec/ so I don't believe so.Guzel
Well, coreutils is a package... But if you don't know what it is, chances are you don't have it.Taconite
I would seriously recommend coreutils though. On OS X you can easily install coreutils with brew install coreutils (requires Homebrew, obviously), then putting coreutils' libexec before /usr/bin in your PATH. I don't want to get into religious conflicts, but after you use coreutils for a while, you'll find BSD utilities shipped with OS X like crippled cousins. Seriously.Taconite
Would it matter which file in runcoms? I was thinking zshrc but don't have much reasoning for that.Guzel
Read man zsh, STARTUP/SHUTDOWN FILES section. It clearly indicates which file is for what. Here you want ls to show colors only in an interactive shell, and it doesn't matter whether it's a login shell or not, so it should go into zshrc.Taconite
Let us continue this discussion in chat.Guzel
A
0

I may be late to the party but I found the answer here: https://github.com/sorin-ionescu/prezto/issues/1539

Run in the Terminal or add to your .zshrc file

export LSCOLORS="ExGxBxDxCxEgEdxbxgxcxd"

Afghani answered 29/10, 2021 at 10:19 Comment(0)
S
0

Only adding this comment in case someone reads this thread in the future.

eleov eleove's answer, while correct, is missing a line before the export LSCOLORS="..." command. You must also include:

export CLICOLOR=1

source: https://infosecmonkey.com/adding-color-to-your-macos-ls-output/

Somber answered 5/6, 2023 at 15:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.