Color ls terminal output for .h, .c, .cpp files

Discussion in 'OS X Mountain Lion (10.8)' started by robertneville77, Sep 19, 2013.

  1. robertneville77 macrumors member

    robertneville77

    Joined:
    Dec 22, 2010
    Location:
    Balmora, Vvardenfell
    #1
    Hi everyone,

    I'm having problems coloring the output of ls for specific filetypes like .c, .h, .cpp, etc. I have some generic coloring for ls working now, i.e. when typing ls in Terminal folders appear blue and executables appear red which is great. But I'd like to add color for other filetypes like those mentioned before. Right now my .bash_profile looks something like this:

    Code:
    export CLICOLOR=1
    export LS_COLORS='ex=35:di=36:ln=31:*.c=32:*.cpp=32:*.cc=32:*.cxx=32:*.h=33:*.hh=33:*.m=32' 
    
    None of those file extensions are getting colored though; they appear black like normal. Any idea on how I can get filetype coloring working?

    Thanks,
    Clint
     
  2. mfram macrumors 65816

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #2
    The man page for 'ls' in 10.8.5 doesn't mention anything about the "LS_COLORS" variable. Only "LSCOLORS". And the man page doesn't mention anything about changing the filename colors based on extension. Only the file type (file, directory, block device, char device, etc.) is mentioned. What you are describing isn't discussed in the man page.
     
  3. robertneville77 thread starter macrumors member

    robertneville77

    Joined:
    Dec 22, 2010
    Location:
    Balmora, Vvardenfell
    #3
    Thanks, I man'd ls too and you are indeed correct. I should probably change that to LSCOLORS. However, I'm still stuck at square one. So that leads me to my next question:

    Does anyone know how to do it with gnu ls?

    I can install coreutils using brew, but I have NO idea how to change the colors of files after that, even though the Linux guys say you can. I've tried following numerous Linux tutorials, and I can't seem to get it working. I think it's a clash between Linux and BSD syntax for bash, so things are slightly off.
     
  4. mfram macrumors 65816

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #4
    GNU coreutils also includes the program 'dircolors'. Look at the output of that utility for an example of the setting.
     

Share This Page