diff options
author | Peter Stephenson <p.stephenson@samsung.com> | 2019-07-10 15:41:24 +0100 |
---|---|---|
committer | Peter Stephenson <p.stephenson@samsung.com> | 2019-07-10 15:41:24 +0100 |
commit | 09385d38ad51477dcc3a20ace67ec50de5fb262e (patch) | |
tree | 29349c255602a5e6d9216912e36aedaf1d764d75 | |
parent | bbcfdffbc33b79688f6daa478bfd9c1171989d15 (diff) | |
download | zsh-09385d38ad51477dcc3a20ace67ec50de5fb262e.tar.gz zsh-09385d38ad51477dcc3a20ace67ec50de5fb262e.tar.xz zsh-09385d38ad51477dcc3a20ace67ec50de5fb262e.zip |
44305: Fix zsh_directory_name_generic
Longest prefix matching was broken if there were suffixes indicating further handling.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | Functions/Chpwd/zsh_directory_name_generic | 23 |
2 files changed, 21 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog index 749d352ba..7b06ec095 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2019-07-10 Peter Stephenson <p.stephenson@samsung.com> + + * 44305: Functions/Chpwd/zsh_directory_name_generic: Longest + prefix matching was broken if there were suffixes indicating + further handling. + 2019-07-09 Peter Stephenson <p.stephenson@samsung.com> * unposted: Etc/FAQ.yo: typo. also updates to outdated notes on 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 _zdn_assoc=(${(Pkv)_zdn_var}) - # Sorting in descending order will ensure prefixes - # come after longer strings with that perfix, so - # we match more specific directory names preferentially. _zdn_cpts=(${(Ov)_zdn_assoc}) _zdn_cpt='' for _zdn_pref_raw in $_zdn_cpts; do _zdn_pref=${_zdn_pref_raw%/:*} [[ -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 fi done + if (( _zdn_matchlen )); then + _zdn_matched+=$_zdn_pref_matched + _zdn_rest=$_zdn_rest_matched + fi if [[ -n $_zdn_cpt ]]; then _zdn_name+=${_zdn_name:+${_zdh_name}:}$_zdn_cpt if [[ ${_zdn_assoc[$_zdn_cpt]} = (#b)*/:([[:IDENT:]]##) ]]; then |