From 1fb1e24112cfae4f03d86b7142904dff2fb2c02c Mon Sep 17 00:00:00 2001 From: "Doster, Vladislav" Date: Thu, 8 Jun 2023 20:58:06 -0500 Subject: [PATCH] fix: zsh impl of `realpath` to handle macOS BSD realpath Signed-off-by: Doster, Vladislav --- .gitignore | 23 +---------------------- Makefile | 6 +++++- doc/zsdoc/zinit-install.zsh.adoc | 25 +++++++++++++++++++------ doc/zsdoc/zinit.zsh.adoc | 1 - zinit-install.zsh | 32 ++++++++++++++++++++++++-------- 5 files changed, 49 insertions(+), 38 deletions(-) diff --git a/.gitignore b/.gitignore index aa8d8e423..7646b6866 100644 --- a/.gitignore +++ b/.gitignore @@ -1,24 +1,3 @@ -*.[aos] -*.bundle -*.dll -*.orig -*.txt -*.zini *.zwc -*deploy*key* -*~ -.*.sw? -.project -TAGS -TODO* -\#* doc/zsdoc/data -other -site*/ -tags -test/ -txt/ -zmodules/ -tests/_output/ -tests/_support/tmp* -.idea +tests/_support/tmp\.* diff --git a/Makefile b/Makefile index cc6ba1137..47c720a7c 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,11 @@ DOC_SRC := $(foreach wrd,$(SRC),../$(wrd)) .PHONY: all clean container doc doc/container tags tags/emacs tags/vim test zwc clean: - rm -rf *.zwc doc/zsdoc/zinit{'','-additional','-autoload','-install','-side'}.zsh.adoc doc/zsdoc/data/ + @rm -rf -- \ + *.zwc \ + tests/_support/tmp* \ + doc/zsdoc/{doc,zinit{'','-additional','-autoload','-install','-side'}.zsh.adoc} \ + container: docker build --tag=ghcr.io/zdharma-continuum/zinit:latest --file=docker/Dockerfile . diff --git a/doc/zsdoc/zinit-install.zsh.adoc b/doc/zsdoc/zinit-install.zsh.adoc index a47515c73..3e6f814aa 100644 --- a/doc/zsdoc/zinit-install.zsh.adoc +++ b/doc/zsdoc/zinit-install.zsh.adoc @@ -24,6 +24,7 @@ Documentation automatically generated with `zshelldoc' .zinit-json-get-value .zinit-json-to-array .zinit-mirror-using-svn + .zinit-realpath .zinit-setup-plugin-dir .zinit-single-line .zinit-update-snippet @@ -193,7 +194,7 @@ ____ ____ -Has 377 line(s). Calls functions: +Has 372 line(s). Calls functions: .zinit-download-snippet |-- .zinit-download-file-stdout @@ -211,10 +212,9 @@ Has 377 line(s). Calls functions: |   `-- zinit.zsh/.zinit-any-to-user-plugin |-- .zinit-mirror-using-svn |-- zinit-side.zsh/.zinit-store-ices - |-- zinit.zsh/+zinit-message - `-- zinit.zsh/is-at-least + `-- zinit.zsh/+zinit-message -Uses feature(s): _is-at-least_, _setopt_, _trap_, _zcompile_ +Uses feature(s): _setopt_, _trap_, _zcompile_ Called by: @@ -458,6 +458,20 @@ Called by: .zinit-download-snippet +==== .zinit-realpath + +____ + + + $1: Initial path + $2: Target path + +____ + +Has 16 line(s). Doesn't call other functions. + +Not called by script or any function (may be e.g. a hook, a Zle widget, etc.). + ==== .zinit-setup-plugin-dir ____ @@ -541,8 +555,7 @@ Has 76 line(s). Calls functions: |   |   `-- zinit.zsh/.zinit-any-to-user-plugin |   |-- .zinit-mirror-using-svn |   |-- zinit-side.zsh/.zinit-store-ices - |   |-- zinit.zsh/+zinit-message - |   `-- zinit.zsh/is-at-least + |   `-- zinit.zsh/+zinit-message |-- zinit.zsh/+zinit-message |-- zinit.zsh/.zinit-get-object-path `-- zinit.zsh/.zinit-pack-ice diff --git a/doc/zsdoc/zinit.zsh.adoc b/doc/zsdoc/zinit.zsh.adoc index e880a8ae6..bd7865e60 100644 --- a/doc/zsdoc/zinit.zsh.adoc +++ b/doc/zsdoc/zinit.zsh.adoc @@ -1965,5 +1965,4 @@ Called by: :zinit-tmp-subst-autoload :zinit-tmp-subst-bindkey Script-Body - zinit-install.zsh/.zinit-download-snippet diff --git a/zinit-install.zsh b/zinit-install.zsh index 54fd880c6..3b5f0a307 100644 --- a/zinit-install.zsh +++ b/zinit-install.zsh @@ -6,7 +6,28 @@ builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh" || { builtin print -P "${ZINIT[col-error]}ERROR:%f%b Couldn't find ${ZINIT[col-obj]}zinit-side.zsh%f%b." return 1 } - +# FUNCTION: .zinit-realpath [[[ +# +# $1: Initial path +# $2: Target path +.zinit-realpath () { + [[ $# -ge 1 ]] && [[ $# -le 2 ]] || return 1 + local target=${${2:-$1}:a} current=${${${2:+$1}:-$PWD}:a} relative='' + local appendix="${target#/}" + while appendix="${target#${current}/}" + [[ $current != '/' ]] && [[ $appendix = $target ]] + do + if [[ $current = $appendix ]]; then + relative="${relative:-.}" + builtin print -- "${relative#/}" + return 0 + fi + current=${current%/*} + relative="$relative${relative:+/}.." + done + relative+=${relative:+${appendix:+/}}${appendix#/} + builtin print -- "$relative" +} # ]]] # FUNCTION: .zinit-jq-check [[[ # Check if jq is available and outputs an error message with instructions if # that's not the case @@ -1198,13 +1219,8 @@ builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh" || { "${${(M)OPTS[opt_-q,--quiet]:#1}:+, skip the -q/--quiet option for more information}.{rst}"; retval=4; } } } else { - if (( $+commands[realpath] )) { - local rpv="$(realpath --version | head -n1 | sed -E 's/realpath (\(.*\))?//g')" - if is-at-least 8.23 $rpv; then - rel_url="$(realpath --relative-to="$local_dir/$dirname" "$url")" && \ - { url="$rel_url" } - fi - } + rel_url="$(.zinit-realpath "$local_dir/$dirname" "$url")" && \ + { url="$rel_url" } if (( !OPTS[opt_-q,--quiet] )) && [[ $url != /dev/null ]] { +zinit-message "{msg}Linking {file}$filename{msg}{…}{rst}" command ln -svf "$url" "$local_dir/$dirname/$filename" || \