diff options
Diffstat (limited to 'tw.color.c')
-rw-r--r-- | tw.color.c | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/tw.color.c b/tw.color.c index 9f12c36f160c..6a12b458f8b6 100644 --- a/tw.color.c +++ b/tw.color.c @@ -157,7 +157,8 @@ static size_t nextensions = 0; static char *colors = NULL; int color_context_ls = FALSE; /* do colored ls */ -static int color_context_lsmF = FALSE; /* do colored ls-F */ +static int color_context_lsmF = FALSE; /* do colored ls-F */ +int color_as_referent = FALSE; /* ln=target in LS_COLORS */ static int getstring (char **, const Char **, Str *, int); static void put_color (const Str *); @@ -201,7 +202,7 @@ getstring(char **dp, const Char **sp, Str *pd, int f) while (*s && (*s & CHAR) != (Char)f && (*s & CHAR) != ':') { if ((*s & CHAR) == '\\' || (*s & CHAR) == '^') { - if ((sc = parseescape(&s)) == CHAR_ERR) + if ((sc = parseescape(&s, TRUE)) == CHAR_ERR) return 0; } else @@ -383,6 +384,9 @@ parseLS_COLORS(const Char *value) if (i < nvariables) { v += 3; getstring(&c, &v, &variables[i].color, ':'); + if (i == VSym) + color_as_referent = strcasecmp( + variables[VSym].color.s, "target") == 0; continue; } else @@ -471,8 +475,28 @@ print_with_color(const Char *filename, size_t len, Char suffix) if (color_context_lsmF && (haderr ? (didfds ? is2atty : isdiagatty) : (didfds ? is1atty : isoutatty))) { - print_color(filename, len, suffix); - xprintf("%S", filename); + + if (suffix == '@' && color_as_referent) { + char *f = short2str(filename); + Char c = suffix; + char buf[MAXPATHLEN + 1]; + + while (c == '@') { + ssize_t b = readlink(f, buf, MAXPATHLEN); + if (b == -1) { + c = '&'; + break; + } + buf[b] = '\0'; + + c = filetype(STRNULL, str2short(buf)); + f = buf; + } + + print_color(filename, len, c); + } else + print_color(filename, len, suffix); + xprintf("%" TCSH_S, filename); if (0 < variables[VEnd].color.len) put_color(&variables[VEnd].color); else { @@ -480,9 +504,8 @@ print_with_color(const Char *filename, size_t len, Char suffix) put_color(&variables[VNormal].color); put_color(&variables[VRight].color); } - } - else - xprintf("%S", filename); + } else + xprintf("%" TCSH_S, filename); xputwchar(suffix); } |