summaryrefslogtreecommitdiff
path: root/src/ls.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2000-04-08 19:03:29 +0000
committerJim Meyering <jim@meyering.net>2000-04-08 19:03:29 +0000
commit5c7059a33aade6ad2b0548f2fcb05f9ede05295c (patch)
tree5958e6a0bf9e77f866bc0c86a2f48e2671c3edf9 /src/ls.c
parent6c60fb0a7ad640f90943430fc6d316f4df47ca2d (diff)
downloadcoreutils-5c7059a33aade6ad2b0548f2fcb05f9ede05295c.tar.xz
Add support for "ln=target" in the LS_COLORS variable,
to colorize links as for the file/directory pointed to.
Diffstat (limited to 'src/ls.c')
-rw-r--r--src/ls.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/src/ls.c b/src/ls.c
index 740598ebf..5728fd1b4 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -297,6 +297,19 @@ static int nfiles;
static int files_index;
+/* When nonzero, in a color listing, color each symlink name according to the
+ type of file it points to. Otherwise, color them according to the `ln'
+ directive in LS_COLORS. Dangling (orphan) symlinks are treated specially,
+ regardless. This is set when `ln=target' appears in LS_COLORS. */
+
+static int color_symlink_as_referent;
+
+/* mode of appropriate file for colorization */
+#define FILE_OR_LINK_MODE(File) \
+ ((color_symlink_as_referent && (File)->linkok) \
+ ? (File)->linkmode : (File)->stat.st_mode)
+
+
/* Record of one pending directory waiting to be listed. */
struct pending
@@ -1588,6 +1601,10 @@ parse_ls_color (void)
}
print_with_color = 0;
}
+
+ if (color_indicator[C_LINK].len == 6
+ && !strncmp (color_indicator[C_LINK].string, "target", 6))
+ color_symlink_as_referent = 1;
}
/* Request that the directory named `name' have its contents listed later.
@@ -2383,7 +2400,7 @@ print_long_format (const struct fileinfo *f)
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)
@@ -2482,7 +2499,7 @@ print_file_name_and_frills (const struct fileinfo *f)
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);