(I've sent a patch along similar lines before, against 3.16. This one's
tidied up, and valid against 4.0, so I hope it's more acceptable now.)
With color-ls, when listing a symlink it can be more useful to color it the
same as the file or directory it points to, rather than using a generic
color for all symlinks (particularly as with "-F" you already get a "@"
sign to show it's a symlink).
With this little patch you can set the color string for LINK to "target",
instead of to a numerical value like "01;36", and it will do this.
Regards,
Alan
P.S. if applying patch against 4.0q rather than 4.0, the G_N_LINES stuff
will be rejected because of the other changes: so here is the updated list
of line lengths.
#define G_N_LINES 91
const size_t G_line_length[G_N_LINES] =
{
65, 72, 0, 59, 61, 0, 77, 10, 12, 15, 12, 14, 14, 14, 14, 13, 13, 13, 13,
13, 13, 10, 17, 9, 11, 13, 10, 0, 73, 64, 18, 64, 19, 72, 25, 72, 68,
22, 22, 71, 73, 17, 19, 17, 34, 39, 45, 0, 44, 10, 0, 70, 75, 48, 0, 73,
40, 11, 11, 11, 11, 0, 48, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
0, 15, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 9, 9
};
===========================================================================
diff -r -u fileutils-4.0-ORIG/src/dircolors.h fileutils-4.0-NEW/src/dircolors.h
--- fileutils-4.0-ORIG/src/dircolors.h Wed Nov 11 04:53:07 1998
+++ fileutils-4.0-NEW/src/dircolors.h Tue Mar 7 14:19:16 2000
@@ -1,12 +1,12 @@
-#define G_N_LINES 76
+#define G_N_LINES 77
const size_t G_line_length[G_N_LINES] =
{
- 65, 72, 0, 59, 61, 0, 77, 10, 12, 14, 14, 14, 14, 13, 13, 13, 13, 13, 13,
- 10, 10, 0, 73, 64, 18, 64, 19, 72, 25, 72, 68, 22, 22, 27, 17, 19, 34,
- 39, 45, 0, 44, 10, 0, 70, 75, 48, 0, 73, 40, 11, 11, 11, 11, 0, 48,
- 10, 10, 10, 10, 10, 10, 10, 10, 10, 26, 10, 10, 10, 10, 10, 10, 10, 10,
- 10, 9, 9
+ 65, 72, 0, 59, 61, 0, 77, 10, 12, 14, 14, 14, 14, 13, 13, 13, 13, 13,
+ 13, 10, 10, 0, 73, 64, 18, 64, 19, 72, 25, 72, 68, 22, 22, 71, 73, 17,
+ 19, 34, 39, 45, 0, 44, 10, 0, 70, 75, 48, 0, 73, 40, 11, 11, 11, 11, 0,
+ 48, 10, 10, 10, 10, 10, 10, 10, 10, 10, 26, 10, 10, 10, 10, 10, 10, 10,
+ 10, 10, 9, 9
};
const char *const G_line[G_N_LINES] =
@@ -44,7 +44,8 @@
"NORMAL 00 # global default, although everything should be something.",
"FILE 00 # normal file",
"DIR 01;34 # directory",
- "LINK 01;36 # symbolic link",
+ "LINK 01;36 # symbolic link. (If you set this to \"target\" instead of a",
+ " # numerical value, the color is as for the file pointed to.)",
"FIFO 40;33 # pipe",
"SOCK 01;35 # socket",
"BLK 40;33;01 # block device driver",
diff -r -u fileutils-4.0-ORIG/src/ls.c fileutils-4.0-NEW/src/ls.c
--- fileutils-4.0-ORIG/src/ls.c Sat Sep 19 18:09:23 1998
+++ fileutils-4.0-NEW/src/ls.c Tue Mar 7 14:19:11 2000
@@ -225,6 +225,17 @@
static int files_index;
+/* Nonzero means in a color listing don't treat symlinks (non-orphaned)
+ specially. Gets set when ":ln=target:" appears in LS_COLORS. */
+
+static int no_special_link_color;
+
+/* mode of appropriate file for colorization */
+#define FILE_OR_LINK_MODE(file) \
+ ((no_special_link_color && (file)->linkok) \
+ ? (file)->linkmode: (file)->stat.st_mode)
+
+
/* Record of one pending directory waiting to be listed. */
struct pending
@@ -1508,6 +1519,9 @@
}
}
+ if (!strncmp(color_indicator[C_LINK].string,"target",6))
+ no_special_link_color=1;
+
if (state < 0)
{
struct col_ext_type *e;
@@ -2329,7 +2343,7 @@
DIRED_INDENT ();
DIRED_FPUTS (buf, stdout, p - buf);
- print_name_with_quoting (f->name, f->stat.st_mode, f->linkok,
+ print_name_with_quoting (f->name,FILE_OR_LINK_MODE(f),f->linkok,
&dired_obstack);
if (f->filetype == symbolic_link)
@@ -2337,8 +2351,8 @@
if (f->linkname)
{
DIRED_FPUTS_LITERAL (" -> ", stdout);
- print_name_with_quoting (f->linkname, f->linkmode, f->linkok - 1,
- NULL);
+ print_name_with_quoting (f->linkname,FILE_OR_LINK_MODE(f),
+ f->linkok - 1,NULL);
if (indicator_style != none)
print_type_indicator (f->linkmode);
}
@@ -2428,7 +2442,7 @@
human_readable ((uintmax_t) ST_NBLOCKS (f->stat), buf,
ST_NBLOCKSIZE, output_block_size));
- print_name_with_quoting (f->name, f->stat.st_mode, f->linkok, NULL);
+ print_name_with_quoting (f->name, FILE_OR_LINK_MODE(f), f->linkok, NULL);
if (indicator_style != none)
print_type_indicator (f->stat.st_mode);