From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4640 invoked from network); 12 May 2008 16:05:59 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.4 (2008-01-01) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.4 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.4 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 12 May 2008 16:05:59 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 27089 invoked from network); 12 May 2008 16:05:54 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 12 May 2008 16:05:54 -0000 Received: (qmail 9214 invoked by alias); 12 May 2008 16:05:50 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25006 Received: (qmail 9202 invoked from network); 12 May 2008 16:05:50 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 12 May 2008 16:05:50 -0000 Received: from cluster-d.mailcontrol.com (cluster-d.mailcontrol.com [217.69.20.190]) by bifrost.dotsrc.org (Postfix) with ESMTP id 5FA9380ED172 for ; Mon, 12 May 2008 18:05:44 +0200 (CEST) Received: from rly47d.srv.mailcontrol.com (localhost.localdomain [127.0.0.1]) by rly47d.srv.mailcontrol.com (MailControl) with ESMTP id m4CG5hYJ031759 for ; Mon, 12 May 2008 17:05:43 +0100 Received: from submission.mailcontrol.com (submission.mailcontrol.com [86.111.216.190]) by rly47d.srv.mailcontrol.com (MailControl) id m4CG4uCV027822 for zsh-workers@sunsite.dk; Mon, 12 May 2008 17:04:56 +0100 Received: from cameurexb01.EUROPE.ROOT.PRI ([62.189.241.200]) by rly47d-eth0.srv.mailcontrol.com (envelope-sender Peter.Stephenson@csr.com) (MIMEDefang) with ESMTP id m4CG4oDh027054; Mon, 12 May 2008 17:04:56 +0100 (BST) Received: from news01 ([10.103.143.38]) by cameurexb01.EUROPE.ROOT.PRI with Microsoft SMTPSVC(6.0.3790.3959); Mon, 12 May 2008 17:04:49 +0100 Date: Mon, 12 May 2008 17:04:49 +0100 From: Peter Stephenson To: sergio Cc: Zsh hackers list Subject: Re: Colored completion listings Message-ID: <20080512170449.45adb932@news01> In-Reply-To: <4828347A.8070503@sergio.spb.ru> References: <4828347A.8070503@sergio.spb.ru> Organization: CSR X-Mailer: Claws Mail 3.3.1 (GTK+ 2.12.5; i386-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-OriginalArrivalTime: 12 May 2008 16:04:49.0881 (UTC) FILETIME=[E80C9490:01C8B449] X-Scanned-By: MailControl A-08-50-00 (www.mailcontrol.com) on 10.68.1.157 X-Virus-Scanned: ClamAV 0.91.2/7102/Mon May 12 15:06:15 2008 on bifrost X-Virus-Status: Clean On Mon, 12 May 2008 16:13:46 +0400 sergio wrote: > Hello. > > I have some troubles with colored completion listing. > > 1) zsh highlights broken symlinks as unbroken. but mi color is defined > and ls highlights it whith correct color. My understanding of ls, and experiment, suggest you mean "or". In other words, in a broken link like: lrwxrwxrwx 1 pws users 12 2008-05-12 16:15 going-nowhere -> non-existent "going-nowhere" uses "or", while "non-existent" uses "mi". As completion doesn't show the target of the symbolic link, only the original name, "mi" is therefore irrelevant in zsh. However, I've fixed "or". (By luck, this is easy with the fix I've just made for ln=target.) If you think I've got this wrong you'll have to point me at chapter and verse. > 2) zsh highlights directories like test.jpg as jpeg file > color for directories is defined before *.jpg Yes, the logic is the wrong way round. File type tests from stat should come before extension tests. (This can be kind of annoying in files from Windows that leave execute permissions all over the place but being compatible with ls is preferable.) Index: Src/Zle/complist.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/Zle/complist.c,v retrieving revision 1.114 diff -u -r1.114 complist.c --- Src/Zle/complist.c 6 May 2008 16:01:19 -0000 1.114 +++ Src/Zle/complist.c 12 May 2008 16:00:30 -0000 @@ -533,9 +533,10 @@ lr_caplen = strlen(mcolors.files[COL_LC]->col) + strlen(mcolors.files[COL_RC]->col); - /* Default for orphans and missing files. Currently not used */ + /* Default for orphan is same as link. */ if (!mcolors.files[COL_OR] || !mcolors.files[COL_OR]->col) - mcolors.files[COL_OR] = mcolors.files[COL_FI]; + mcolors.files[COL_OR] = mcolors.files[COL_LN]; + /* Default for missing files: currently not used */ if (!mcolors.files[COL_MI] || !mcolors.files[COL_MI]->col) mcolors.files[COL_MI] = mcolors.files[COL_FI]; @@ -871,36 +872,15 @@ * file modes. */ static int -putfilecol(char *group, char *n, mode_t m) +putfilecol(char *group, char *n, mode_t m, int special) { - int colour; + int colour = -1; Extcol ec; Patcol pc; - for (ec = mcolors.exts; ec; ec = ec->next) - if (strsfx(ec->ext, n) && - (!ec->prog || !group || pattry(ec->prog, group))) { - zlrputs(ec->col); - - return 0; - } - - nrefs = MAX_POS - 1; - - for (pc = mcolors.pats; pc; pc = pc->next) - if ((!pc->prog || !group || pattry(pc->prog, group)) && - pattryrefs(pc->pat, n, -1, -1, 0, &nrefs, begpos, endpos)) { - if (pc->cols[1]) { - patcols = pc->cols; - - return 1; - } - zlrputs(pc->cols[0]); - - return 0; - } - - if (S_ISDIR(m)) { + if (special != -1) { + colour = special; + } else if (S_ISDIR(m)) { if (m & S_IWOTH) if (m & S_ISVTX) colour = COL_TW; @@ -926,10 +906,36 @@ colour = COL_SG; else if (S_ISREG(m) && (m & S_IXUGO)) colour = COL_EX; - else - colour = COL_FI; - zcputs(group, colour); + if (colour != -1) { + zcputs(group, colour); + return 0; + } + + for (ec = mcolors.exts; ec; ec = ec->next) + if (strsfx(ec->ext, n) && + (!ec->prog || !group || pattry(ec->prog, group))) { + zlrputs(ec->col); + + return 0; + } + + nrefs = MAX_POS - 1; + + for (pc = mcolors.pats; pc; pc = pc->next) + if ((!pc->prog || !group || pattry(pc->prog, group)) && + pattryrefs(pc->pat, n, -1, -1, 0, &nrefs, begpos, endpos)) { + if (pc->cols[1]) { + patcols = pc->cols; + + return 1; + } + zlrputs(pc->cols[0]); + + return 0; + } + + zcputs(group, COL_FI); return 0; } @@ -1752,10 +1758,17 @@ else if (mselect >= 0 && (m->flags & (CMF_MULT | CMF_FMULT))) zcputs(g->name, COL_DU); else if (m->mode) { + /* + * Symlink is orphaned if we read the mode with lstat + * but couldn't read one with stat. That's the + * only way they can be different so the following + * test should be enough. + */ + int orphan_colour = (m->mode && !m->fmode) ? COL_OR : -1; if (mcolors.flags & LC_FOLLOW_SYMLINKS) { - subcols = putfilecol(g->name, m->str, m->fmode); + subcols = putfilecol(g->name, m->str, m->fmode, orphan_colour); } else { - subcols = putfilecol(g->name, m->str, m->mode); + subcols = putfilecol(g->name, m->str, m->mode, orphan_colour); } } else