Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tree uncolorized #3951

Closed
FranklinYu opened this issue Jun 4, 2015 · 11 comments
Closed

tree uncolorized #3951

FranklinYu opened this issue Jun 4, 2015 · 11 comments

Comments

@FranklinYu
Copy link
Contributor

The output of tree should be colorized only for terminal (similar to --color=auto). This is the default case in zsh, but Oh-My-Zsh suppresses it.

@mcornella
Copy link
Member

I don't know if I understood correctly: in your system, tree appears with colors even when you're not in the terminal? Or it doesn't show colors at all?

In my system (Debian with zsh 5.0.7) the correct behavior appears: tree shows with colors, but tree > tree_sample.txt only outputs text.

@apjanke
Copy link
Contributor

apjanke commented Jun 6, 2015

I can reproduce behavior that sounds similar to this. On my OS X 10.9.5 system (zsh 5.0.2, tree 1.7.0) and my Debian 7 system (zsh 4.3.17, tree 1.6.0), when I run tree from a zsh session, the output is not colorized unless I force it with tree -C.

But I don't think it's due to oh-my-zsh per se. I get the same behavior under zsh if I disable oh-my-zsh.

I suspect it's because OP's setup does not define LS_COLORS. tree uses LS_COLORS (and not LSCOLORS) to decide whether it should colorize. From the man page:

DESCRIPTION
       Tree is a recursive directory listing program that produces a depth indented listing
       of  files, which is colorized ala dircolors if the LS_COLORS environment variable is
       set and output is to tty.

Zsh does not in fact set up LS_COLORS by default, and neither does oh-my-zsh. Some of the oh-my-zsh themes define it, though.

@FranklinYu, check your $LS_COLORS to see if it's defined and if not, define it in your ~/.zshrc or switch to an OMZ theme that does.

Was it working under zsh before you installed oh-my-zsh? Installing oh-my-zsh will replace your existing ~/.zshrc file, moving it to ~/.zshrc.pre-oh-my-zsh. If you previously had a .zshrc that defined LS_COLORS, that would explain why it stopped working with OMZ. To fix that, restore your original .zshrc configuration: copy the current ~/.zshrc contents to the end of ~/.zshrc.pre-oh-my-zsh and then move ~/.zshrc.pre-oh-my-zsh to ~/.zshrc.

@FranklinYu
Copy link
Contributor Author

@apjanke LS_COLORS is defined exactly the same as my Bash; in contrast, LSCOLORS shows junk. I uninstalled Oh-My-Zsh and tree works fine. In contrast, ls becomes something like ls --color=never (same as in bash) and I need a alias ls='ls --color=auto'. For your reference, this is my LS_COLORS:

rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:

It looks just fine.

@FranklinYu
Copy link
Contributor Author

@mcornella It does not display color at all, unless I manually -C. I am on Ubuntu 14.04 with Zsh 5.0.2 and tree 1.6.0

@apjanke
Copy link
Contributor

apjanke commented Jun 6, 2015

Hmm. Let's see if we can get some more details about your setup.

What do you mean by "LSCOLORS shows junk"? Is it the value of LSCOLORS itself that looks bad?

Could you run the omz_diagnostic_dump function from this file and post the output as a gist?

@FranklinYu
Copy link
Contributor Author

@apjanke You are right about LS_COLORS. I accidentally found something; now I summarize the cases so far:

  1. In clean Zsh, LS_COLORS is set, and tree works fine.
  2. After I installed Oh-My-Zsh, LS_COLORS is gone and tree doesn't work.
  3. If I set bash as my default shell, and I enter zsh from that, then everything works fine again, including the LS_COLORS.
  4. If Zsh is my default, then tree and LS_COLORS doesn't works (as stated in case 2), but if I enter bash and then zsh, then tree and LS_COLORS gets back to normal in the inner zsh.
  5. In the only failing case (No. 2), export LS_COLORS='settings...' works as expected.

Therefore, I am pretty sure I need an export or something similar in some of my rc files, but should I add them to the .zshrc? Why re-entering Zsh sets the LS_COLORS? (I cannot find the setting in .bashrc or .profile.)

I guess I do not need to post the dump? 😄

@apjanke
Copy link
Contributor

apjanke commented Jun 6, 2015

LS_COLORS is not set by default in zsh. It needs to be set in config or rc files. There are different rc files for bash and zsh.

I bet it was set in your old ~/.zshrc, which oh-my-zsh moves out of the way when it installs. Look in your home directory for ~/.zshrc-pre-oh-my-zsh and if it's there, copy all the stuff in it over to your current ~/.zshrc.

Please post the dump; it will still be useful.

@FranklinYu
Copy link
Contributor Author

FranklinYu commented Jun 6, 2015

Yes, I found it: my ~/.zshrc contains a line eval "$(dircolors -b)" which will set the colors.

And now I know why the inner Zsh works in the case 3 and 4: it inherits the LS_COLORS from Bash.

For your reference, the dump is at this gist (of course it is before I ~/.zshrc.pre-oh-my-zsh into ~/.zshrc).

@apjanke
Copy link
Contributor

apjanke commented Jun 6, 2015

Great. Thanks for the info.

Could you close this issue if it's working now? (Only the original poster and repo owner have rights to close issues.)

@FranklinYu
Copy link
Contributor Author

Yes, sure. Great thanks. In addition, merging everything from ~/.zshrc.pre-oh-my-zsh to the top of ~/.zshrc suppresses Oh-My-Zsh, so I only copy the line that gets me the colors (and sure it works). I guess these lines are not overridden in following settings:

autoload -Uz promptinit
promptinit
prompt adam1

@xuhdev
Copy link
Contributor

xuhdev commented Oct 3, 2016

FYI, I've made a PR to make oh-my-zsh set LS_COLORS by default #5488

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants