Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Below is a sample of my dircolors file, I want subversion folders (.svn) to be colored, but i guess the extension section only applies to file names.

How do i set colors for directories with certain names?

NORMAL 00   # global default, although everything should be something.
FILE   00   # normal file
DIR    35   # directory
LINK   01;36    # symbolic link
FIFO   40;33    # pipe
SOCK   01;35    # socket
BLK    40;33;01 # block device driver
CHR    40;33;01 # character device driver

# This is for files with execute permission:
EXEC 01;32

# List any file extensions like '.gz' or '.tar' that you would like ls
# to colorize below. Put the extension, a space, and the color init string.
# (and any comments you want to add after a '#')
*~    01;33;41 # stuff we hate to find laying around (flashing red)
.svn  37
.cmd  01;32 # executables (bright green)
.exe  01;32
.com  01;32
.btm  01;32
share|improve this question
    
What OS? I’m unfamiliar with dircolors. –  Chris Page Jul 4 '12 at 3:47
    
This answer stackoverflow.com/a/11288821/754997 uses a Perl script to colorize the output from ls. You then use that script instead of ls. –  Chris Page Jul 4 '12 at 3:51

1 Answer 1

up vote 5 down vote accepted

I found a way:

diff --git a/src/ls.c b/src/ls.c
index 680a7c3..d316eb6 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -4226,7 +4226,7 @@ print_color_indicator (const struct fileinfo *f, bool symlink_target)

   /* Check the file's suffix only if still classified as C_FILE.  */
   ext = NULL;
-  if (type == C_FILE)
+  if (type == C_FILE || type == C_DIR)
     {
       /* Test if NAME has a recognized suffix.  */

enter image description here

share|improve this answer
    
Notice that without modifying ls source code, what you are asking for is not possible. (See the first comment /* … */ above.) –  Stéphane Gimenez Jul 31 '11 at 0:01
    
Thanks, so i guess i won't be modifying the source code (i don't have that level of access on the machines at work. –  Roy Rico Jul 31 '11 at 3:10
1  
@Roy: There is nothing that prevents you from compiling your own ls and place it in your PATH. Quite easy: git clone git://git.sv.gnu.org/coreutils, edit one line of src/ls.c, ./bootstrap, ./configure, make, cp src/ls ~/bin, and you're done :-) –  Stéphane Gimenez Jul 31 '11 at 3:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.