help / color / Atom feed
From: Peter Stephenson <p.stephenson@samsung.com>
To: Zsh Hackers' List <zsh-workers@zsh.org>
Subject: PATCH: zsh_directiory_name_generic fix
Date: Wed, 10 Jul 2019 15:31:13 +0100
Message-ID: <1562769073.6491.10.camel@samsung.com> (raw)
In-Reply-To: <CGME20190710143114eucas1p1a5939118c365d5a25d81881dbef5dc44@eucas1p1.samsung.com>

There was a bug in matching directories back to compentised names that
it didn't prefer longest matches of prefixes if the prefix contained an
expression that would be match as a new component, because it was
sorting on the raw values (i.e. including the :more_stuff suffix).  This
does the simple thing of matching exhaustively and picking the longest
prefix that matches.


diff --git a/Functions/Chpwd/zsh_directory_name_generic b/Functions/Chpwd/zsh_directory_name_generic
index aa4bf9b84..df21af598 100644
--- a/Functions/Chpwd/zsh_directory_name_generic
+++ b/Functions/Chpwd/zsh_directory_name_generic
@@ -69,25 +69,32 @@ elif [[ $1 = d ]]; then
   local _zdn_rest=$_zdn_dir
   local -a _zdn_cpts
   local _zdn_pref _zdn_pref_raw _zdn_matched _zdn_cpt _zdn_name
+  local _zdn_pref_matched _zdn_rest_matched
+  integer _zdn_matchlen _zdn_len1
   while [[ -n $_zdn_var && -n $_zdn_rest ]]; do
+    _zdn_matchlen=0
-    # Sorting in descending order will ensure prefixes
-    # come after longer strings with that perfix, so
-    # we match more specific directory names preferentially.
     for _zdn_pref_raw in $_zdn_cpts; do
       [[ -z $_zdn_pref ]] && continue
       if [[ $_zdn_rest = $_zdn_pref(#b)(/|)(*) ]]; then
-	_zdn_cpt=${(k)_zdn_assoc[(r)$_zdn_pref_raw]}
-	# if we matched a /, too, add it...
-	_zdn_matched+=$_zdn_pref$match[1]
-	_zdn_rest=$match[2]
-	break
+        _zdn_len1=${#_zdn_pref}
+	if (( _zdn_len1 > _zdn_matchlen )); then
+	  _zdn_matchlen=$_zdn_len1
+	  _zdn_cpt=${(k)_zdn_assoc[(r)$_zdn_pref_raw]}
+	  # if we matched a /, too, add it...
+	  _zdn_pref_matched=$_zdn_pref$match[1]
+	  _zdn_rest_matched=$match[2]
+	fi
+    if (( _zdn_matchlen )); then
+      _zdn_matched+=$_zdn_pref_matched
+      _zdn_rest=$_zdn_rest_matched
+    fi
     if [[ -n $_zdn_cpt ]]; then
       if [[ ${_zdn_assoc[$_zdn_cpt]} = (#b)*/:([[:IDENT:]]##) ]]; then

           reply index

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <CGME20190710143114eucas1p1a5939118c365d5a25d81881dbef5dc44@eucas1p1.samsung.com>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1562769073.6491.10.camel@samsung.com \
    --to=p.stephenson@samsung.com \
    --cc=zsh-workers@zsh.org \


* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link


Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-workers

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git