From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 28654 invoked by alias); 4 Oct 2015 17:06:13 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 36771 Received: (qmail 6776 invoked from network); 4 Oct 2015 17:06:12 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.0 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:message-id:date:in-reply-to:comments :references:to:subject:mime-version:content-type; bh=w3KDPeLgVeuKzaX1/c7CsLyg/HA6QdNTSj6axdzRcXw=; b=cEaTupq3zUOTrfwkOwuAvOT9vh/iwEZ6DZe7ufvrxNZMhwnFgcyep/7onaFMAPI260 loVtbRgymtzZPAvrRznP0/7PHcVsGZHBQd437Mu47FebaArGRdgyKL/hYdcp52eoee6g oTLVBGbXANPxtNhkEgosc9EWGeU4+D5bWhs+j6zom3urqpEzJnWOudQY4gzqg1MjfLY3 +4TcYIqKtsz7z2BVupifpriuBnOpb4JKCOYIxX/KDSw8UYG3p1kao/+j2toAcSSIZgmF qeOyDlK0pd3DizSQnZGf04zrIFiTZIHihlYxCEc3wfwE6UAvySFnlCcW5i5u5CLAAIcM UD0A== X-Gm-Message-State: ALoCoQnc4BDNlb25QBB1fF9+8ZUzoGFiuneY1ytSQGig58+YJYnq381Po4xup3bKzydOyj7Xxx9+ X-Received: by 10.202.215.136 with SMTP id o130mr1249489oig.85.1443978368441; Sun, 04 Oct 2015 10:06:08 -0700 (PDT) From: Bart Schaefer Message-Id: <151004100604.ZM3726@torch.brasslantern.com> Date: Sun, 4 Oct 2015 10:06:04 -0700 In-Reply-To: <20151004121721.GA2341@zira.vinc17.org> Comments: In reply to Vincent Lefevre "Re: annoying correction of directory name to non-directory name for cd" (Oct 4, 2:17pm) References: <20150916232123.GA17398@zira.vinc17.org> <150916180714.ZM9139@torch.brasslantern.com> <20151004121721.GA2341@zira.vinc17.org> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: zsh-workers@zsh.org Subject: Re: annoying correction of directory name to non-directory name for cd MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii On Oct 4, 2:17pm, Vincent Lefevre wrote: } Subject: Re: annoying correction of directory name to non-directory name f } } On 2015-09-16 18:07:14 -0700, Bart Schaefer wrote: } > On Sep 17, 1:21am, Vincent Lefevre wrote: } > } zsh often proposes to correct a directory name to a non-directory } > } name. This is annoying. } > } > CORRECT_ALL isn't intended to be that smart. } } For the simplest cases, it doesn't need to know the meaning: when the } word is followed by a slash, the filename must be a directory name. Hmm. Does this do what you want? I've tried to minimize the stat()-ing to the names that are actually candidate corrections. diff --git a/Src/utils.c b/Src/utils.c index ab3b0c2..530b51e 100644 --- a/Src/utils.c +++ b/Src/utils.c @@ -2812,7 +2812,7 @@ spckword(char **s, int hist, int cmd, int ask) * as used in spscan(), so that an autocd is chosen * * only when it is better than anything so far, and * * so we prefer directories earlier in the cdpath. */ - if ((thisdist = mindist(*pp, *s, bestcd)) < d) { + if ((thisdist = mindist(*pp, *s, bestcd, 1)) < d) { best = dupstring(bestcd); d = thisdist; } @@ -4057,7 +4057,8 @@ spname(char *oldname) thresh = 3; else if (thresh > 100) thresh = 100; - if ((thisdist = mindist(newname, spnameguess, spnamebest)) >= thresh) { + thisdist = mindist(newname, spnameguess, spnamebest, *old == '/'); + if (thisdist >= thresh) { /* The next test is always true, except for the first path * * component. We could initialize bestdist to some large * * constant instead, and then compare to that constant here, * @@ -4082,12 +4083,13 @@ spname(char *oldname) /**/ static int -mindist(char *dir, char *mindistguess, char *mindistbest) +mindist(char *dir, char *mindistguess, char *mindistbest, int isdir) { int mindistd, nd; DIR *dd; char *fn; char *buf; + struct stat st; if (dir[0] == '\0') dir = "."; @@ -4096,7 +4098,7 @@ mindist(char *dir, char *mindistguess, char *mindistbest) buf = zalloc(strlen(dir) + strlen(mindistguess) + 2); sprintf(buf, "%s/%s", dir, mindistguess); - if (access(unmeta(buf), F_OK) == 0) { + if (stat(unmeta(buf), &st) == 0 && (!isdir || S_ISDIR(st.st_mode))) { strcpy(mindistbest, mindistguess); free(buf); return 0; @@ -4110,7 +4112,8 @@ mindist(char *dir, char *mindistguess, char *mindistbest) continue; nd = spdist(fn, mindistguess, (int)strlen(mindistguess) / 4 + 1); - if (nd <= mindistd) { + if (nd <= mindistd && + (!isdir || (stat(unmeta(fn), &st) == 0 && S_ISDIR(st.st_mode)))) { strcpy(mindistbest, fn); mindistd = nd; if (mindistd == 0)