mirror of
git://git.code.sf.net/p/zsh/code
synced 2025-10-03 08:11:03 +02:00
24951: implement ZLS_COLORS ln=target
This commit is contained in:
parent
da037f7393
commit
dbe5fd93a7
5 changed files with 78 additions and 30 deletions
|
@ -5,6 +5,9 @@
|
||||||
|
|
||||||
2008-05-06 Peter Stephenson <pws@csr.com>
|
2008-05-06 Peter Stephenson <pws@csr.com>
|
||||||
|
|
||||||
|
* 24951: Doc/Zsh/mod_complist, Src/Zle/comp.h, Src/Zle/compcore.c,
|
||||||
|
Src/Zle/complist.c: implement ZLS_COLORS ln=target.
|
||||||
|
|
||||||
* 24937, 24938: Dag-Erling Smørgrav <des@des.no>: configure.ac:
|
* 24937, 24938: Dag-Erling Smørgrav <des@des.no>: configure.ac:
|
||||||
improved version of 24972.
|
improved version of 24972.
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,9 @@ item(tt(di 32))(
|
||||||
for directories
|
for directories
|
||||||
)
|
)
|
||||||
item(tt(ln 36))(
|
item(tt(ln 36))(
|
||||||
for symbolic links
|
for symbolic links. If this has the special value tt(target),
|
||||||
|
symbolic links are dereferenced and the target file used to
|
||||||
|
determine the display format.
|
||||||
)
|
)
|
||||||
item(tt(pi 31))(
|
item(tt(pi 31))(
|
||||||
for named pipes (FIFOs)
|
for named pipes (FIFOs)
|
||||||
|
|
|
@ -114,6 +114,8 @@ struct cmatch {
|
||||||
int gnum; /* global number */
|
int gnum; /* global number */
|
||||||
mode_t mode; /* mode field of a stat */
|
mode_t mode; /* mode field of a stat */
|
||||||
char modec; /* LIST_TYPE-character for mode or nul */
|
char modec; /* LIST_TYPE-character for mode or nul */
|
||||||
|
mode_t fmode; /* mode field of a stat, following symlink */
|
||||||
|
char fmodec; /* LIST_TYPE-character for fmode or nul */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CMF_FILE (1<< 0) /* this is a file */
|
#define CMF_FILE (1<< 0) /* this is a file */
|
||||||
|
|
|
@ -2784,8 +2784,8 @@ add_match_data(int alt, char *str, char *orig, Cline line,
|
||||||
(complist ?
|
(complist ?
|
||||||
((strstr(complist, "packed") ? CMF_PACKED : 0) |
|
((strstr(complist, "packed") ? CMF_PACKED : 0) |
|
||||||
(strstr(complist, "rows") ? CMF_ROWS : 0)) : 0));
|
(strstr(complist, "rows") ? CMF_ROWS : 0)) : 0));
|
||||||
cm->mode = 0;
|
cm->mode = cm->fmode = 0;
|
||||||
cm->modec = '\0';
|
cm->modec = cm->fmodec = '\0';
|
||||||
if ((flags & CMF_FILE) && orig[0] && orig[strlen(orig) - 1] != '/') {
|
if ((flags & CMF_FILE) && orig[0] && orig[strlen(orig) - 1] != '/') {
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
char *pb;
|
char *pb;
|
||||||
|
@ -2799,6 +2799,11 @@ add_match_data(int alt, char *str, char *orig, Cline line,
|
||||||
if ((cm->modec = file_type(buf.st_mode)) == ' ')
|
if ((cm->modec = file_type(buf.st_mode)) == ' ')
|
||||||
cm->modec = '\0';
|
cm->modec = '\0';
|
||||||
}
|
}
|
||||||
|
if (!ztat(pb, &buf, 0)) {
|
||||||
|
cm->fmode = buf.st_mode;
|
||||||
|
if ((cm->fmodec = file_type(buf.st_mode)) == ' ')
|
||||||
|
cm->fmodec = '\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ((*compqstack == QT_BACKSLASH && compqstack[1]) ||
|
if ((*compqstack == QT_BACKSLASH && compqstack[1]) ||
|
||||||
(autoq && *compqstack && compqstack[1] == QT_BACKSLASH))
|
(autoq && *compqstack && compqstack[1] == QT_BACKSLASH))
|
||||||
|
@ -3208,6 +3213,8 @@ dupmatch(Cmatch m, int nbeg, int nend)
|
||||||
r->disp = ztrdup(m->disp);
|
r->disp = ztrdup(m->disp);
|
||||||
r->mode = m->mode;
|
r->mode = m->mode;
|
||||||
r->modec = m->modec;
|
r->modec = m->modec;
|
||||||
|
r->fmode = m->fmode;
|
||||||
|
r->fmodec = m->fmodec;
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
|
@ -108,12 +108,6 @@ static int mtab_been_reallocated;
|
||||||
* as mtab and mmtabp.
|
* as mtab and mmtabp.
|
||||||
*/
|
*/
|
||||||
static Cmgroup *mgtab, *mgtabp;
|
static Cmgroup *mgtab, *mgtabp;
|
||||||
/*
|
|
||||||
* Contains information about the colours to be used for entries.
|
|
||||||
* Sometimes mcolors is passed as an argument even though it's
|
|
||||||
* available to all the functions.
|
|
||||||
*/
|
|
||||||
static struct listcols mcolors;
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
/*
|
/*
|
||||||
* Allow us to keep track of pointer arithmetic for mgtab; could
|
* Allow us to keep track of pointer arithmetic for mgtab; could
|
||||||
|
@ -248,12 +242,26 @@ struct extcol {
|
||||||
|
|
||||||
typedef struct listcols *Listcols;
|
typedef struct listcols *Listcols;
|
||||||
|
|
||||||
|
/* values for listcol flags */
|
||||||
|
enum {
|
||||||
|
/* ln=target: follow symlinks to determine highlighting */
|
||||||
|
LC_FOLLOW_SYMLINKS = 0x0001
|
||||||
|
};
|
||||||
|
|
||||||
struct listcols {
|
struct listcols {
|
||||||
Filecol files[NUM_COLS]; /* strings for file types */
|
Filecol files[NUM_COLS]; /* strings for file types */
|
||||||
Patcol pats; /* strings for patterns */
|
Patcol pats; /* strings for patterns */
|
||||||
Extcol exts; /* strings for extensions */
|
Extcol exts; /* strings for extensions */
|
||||||
|
int flags; /* special settings, see above */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Contains information about the colours to be used for entries.
|
||||||
|
* Sometimes mcolors is passed as an argument even though it's
|
||||||
|
* available to all the functions.
|
||||||
|
*/
|
||||||
|
static struct listcols mcolors;
|
||||||
|
|
||||||
/* Combined length of LC and RC, maximum length of capability strings. */
|
/* Combined length of LC and RC, maximum length of capability strings. */
|
||||||
|
|
||||||
static int lr_caplen, max_caplen;
|
static int lr_caplen, max_caplen;
|
||||||
|
@ -428,24 +436,33 @@ getcoldef(char *s)
|
||||||
for (i = 0, nn = colnames; *nn; i++, nn++)
|
for (i = 0, nn = colnames; *nn; i++, nn++)
|
||||||
if (!strcmp(n, *nn))
|
if (!strcmp(n, *nn))
|
||||||
break;
|
break;
|
||||||
p = getcolval(s, 0);
|
/*
|
||||||
if (*nn) {
|
* special case: highlighting link targets
|
||||||
Filecol fc, fo;
|
*/
|
||||||
|
if (i == COL_LN && strpfx("target", s) &&
|
||||||
|
(s[6] == ':' || !s[6])) {
|
||||||
|
mcolors.flags |= LC_FOLLOW_SYMLINKS;
|
||||||
|
p = s + 6;
|
||||||
|
} else {
|
||||||
|
p = getcolval(s, 0);
|
||||||
|
if (*nn) {
|
||||||
|
Filecol fc, fo;
|
||||||
|
|
||||||
fc = (Filecol) zhalloc(sizeof(*fc));
|
fc = (Filecol) zhalloc(sizeof(*fc));
|
||||||
fc->prog = (i == COL_EC || i == COL_LC || i == COL_RC ?
|
fc->prog = (i == COL_EC || i == COL_LC || i == COL_RC ?
|
||||||
NULL : gprog);
|
NULL : gprog);
|
||||||
fc->col = s;
|
fc->col = s;
|
||||||
fc->next = NULL;
|
fc->next = NULL;
|
||||||
if ((fo = mcolors.files[i])) {
|
if ((fo = mcolors.files[i])) {
|
||||||
while (fo->next)
|
while (fo->next)
|
||||||
fo = fo->next;
|
fo = fo->next;
|
||||||
fo->next = fc;
|
fo->next = fc;
|
||||||
} else
|
} else
|
||||||
mcolors.files[i] = fc;
|
mcolors.files[i] = fc;
|
||||||
|
}
|
||||||
|
if (*p)
|
||||||
|
*p++ = '\0';
|
||||||
}
|
}
|
||||||
if (*p)
|
|
||||||
*p++ = '\0';
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -474,6 +491,7 @@ getcols()
|
||||||
int i, l;
|
int i, l;
|
||||||
|
|
||||||
max_caplen = lr_caplen = 0;
|
max_caplen = lr_caplen = 0;
|
||||||
|
mcolors.flags = 0;
|
||||||
queue_signals();
|
queue_signals();
|
||||||
if (!(s = getsparam("ZLS_COLORS")) &&
|
if (!(s = getsparam("ZLS_COLORS")) &&
|
||||||
!(s = getsparam("ZLS_COLOURS"))) {
|
!(s = getsparam("ZLS_COLOURS"))) {
|
||||||
|
@ -1685,7 +1703,7 @@ clprintm(Cmgroup g, Cmatch *mp, int mc, int ml, int lastc, int width)
|
||||||
}
|
}
|
||||||
zcoff();
|
zcoff();
|
||||||
} else {
|
} else {
|
||||||
int mx;
|
int mx, modec;
|
||||||
|
|
||||||
if (g->widths) {
|
if (g->widths) {
|
||||||
int i;
|
int i;
|
||||||
|
@ -1733,8 +1751,13 @@ clprintm(Cmgroup g, Cmatch *mp, int mc, int ml, int lastc, int width)
|
||||||
zcputs(g->name, COL_HI);
|
zcputs(g->name, COL_HI);
|
||||||
else if (mselect >= 0 && (m->flags & (CMF_MULT | CMF_FMULT)))
|
else if (mselect >= 0 && (m->flags & (CMF_MULT | CMF_FMULT)))
|
||||||
zcputs(g->name, COL_DU);
|
zcputs(g->name, COL_DU);
|
||||||
else if (m->mode)
|
else if (m->mode) {
|
||||||
subcols = putfilecol(g->name, m->str, m->mode);
|
if (mcolors.flags & LC_FOLLOW_SYMLINKS) {
|
||||||
|
subcols = putfilecol(g->name, m->str, m->fmode);
|
||||||
|
} else {
|
||||||
|
subcols = putfilecol(g->name, m->str, m->mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
subcols = putmatchcol(g->name, (m->disp ? m->disp : m->str));
|
subcols = putmatchcol(g->name, (m->disp ? m->disp : m->str));
|
||||||
|
|
||||||
|
@ -1747,12 +1770,13 @@ clprintm(Cmgroup g, Cmatch *mp, int mc, int ml, int lastc, int width)
|
||||||
len = ZMB_nicewidth(m->disp ? m->disp : m->str);
|
len = ZMB_nicewidth(m->disp ? m->disp : m->str);
|
||||||
mlprinted = len ? (len-1) / columns : 0;
|
mlprinted = len ? (len-1) / columns : 0;
|
||||||
|
|
||||||
if ((g->flags & CGF_FILES) && m->modec) {
|
modec = (mcolors.flags & LC_FOLLOW_SYMLINKS) ? m->fmodec : m->modec;
|
||||||
|
if ((g->flags & CGF_FILES) && modec) {
|
||||||
if (m->gnum != mselect) {
|
if (m->gnum != mselect) {
|
||||||
zcoff();
|
zcoff();
|
||||||
zcputs(g->name, COL_TC);
|
zcputs(g->name, COL_TC);
|
||||||
}
|
}
|
||||||
putc(m->modec, shout);
|
putc(modec, shout);
|
||||||
len++;
|
len++;
|
||||||
}
|
}
|
||||||
if ((len = width - len - 2) > 0) {
|
if ((len = width - len - 2) > 0) {
|
||||||
|
@ -2556,6 +2580,15 @@ domenuselect(Hookdef dummy, Chdata dat)
|
||||||
s->origcs = origcs;
|
s->origcs = origcs;
|
||||||
s->origll = origll;
|
s->origll = origll;
|
||||||
s->status = dupstring(status);
|
s->status = dupstring(status);
|
||||||
|
/*
|
||||||
|
* with just the slightest hint of a note of infuriation:
|
||||||
|
* mode here is the menu mode, not the file mode, despite
|
||||||
|
* the fact we're in a file dealing with file highlighting;
|
||||||
|
* but that's OK, because s is a menu stack entry, despite
|
||||||
|
* the fact we're in a function declaring s as char *.
|
||||||
|
* anyway, in functions we really mean *mode* it's
|
||||||
|
* called m, to be clear.
|
||||||
|
*/
|
||||||
s->mode = mode;
|
s->mode = mode;
|
||||||
menucmp = menuacc = hasoldlist = 0;
|
menucmp = menuacc = hasoldlist = 0;
|
||||||
minfo.cur = NULL;
|
minfo.cur = NULL;
|
||||||
|
@ -2674,6 +2707,7 @@ domenuselect(Hookdef dummy, Chdata dat)
|
||||||
s->origcs = origcs;
|
s->origcs = origcs;
|
||||||
s->origll = origll;
|
s->origll = origll;
|
||||||
s->status = dupstring(status);
|
s->status = dupstring(status);
|
||||||
|
/* see above */
|
||||||
s->mode = mode;
|
s->mode = mode;
|
||||||
accept_last();
|
accept_last();
|
||||||
handleundo();
|
handleundo();
|
||||||
|
|
Loading…
Reference in a new issue