diff --git a/doc/zsdoc/zinit-install.zsh.adoc b/doc/zsdoc/zinit-install.zsh.adoc index d1b7efc46..ccf1969c0 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/+zi-log - `-- zinit.zsh/is-at-least + `-- zinit.zsh/+zi-log -Uses feature(s): _is-at-least_, _setopt_, _trap_, _zcompile_ +Uses feature(s): _setopt_, _trap_, _zcompile_ Called by: @@ -457,6 +457,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 ____ @@ -540,8 +554,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/+zi-log - |   `-- zinit.zsh/is-at-least + |   `-- zinit.zsh/+zi-log |-- zinit.zsh/+zi-log |-- 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 31d7a7108..e2445ba02 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/tests/commands.zunit b/tests/commands.zunit index 6a109b8f7..f507b13af 100644 --- a/tests/commands.zunit +++ b/tests/commands.zunit @@ -59,4 +59,4 @@ assert $state equals 0 } -# vim:ft=zsh:sw=2:sts=2:et:foldmarker={,}:foldmethod=marker +# vim:ft=zsh:sw=2:sts=2:et:foldmarker={,}:foldmethod=marker \ No newline at end of file diff --git a/zinit-install.zsh b/zinit-install.zsh index 8d8679ad8..94f746511 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 @@ -1194,34 +1215,38 @@ builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh" || { "accessible (wrong permissions).{rst}" retval=4 } - if ! (( ${+ICE[link] )) { - if (( !OPTS[opt_-q,--quiet] )) && [[ $url != /dev/null ]] { + + + if ! (( ${+ICE[link]} )); then + if (( !OPTS[opt_-q,--quiet] )) && [[ $url != /dev/null ]]; then +zi-log "{msg}Copying {file}$filename{msg}{…}{rst}" - command cp -vf "$url" "$local_dir/$dirname/$filename" || \ - { +zi-log "{ehi}ERROR:{error} The file copying has been unsuccessful.{rst}"; retval=4; } - } else { - command cp -f "$url" "$local_dir/$dirname/$filename" &>/dev/null || \ - { +zi-log "{ehi}ERROR:{error} The copying of {file}$filename{error} has been unsuccessful"\ - "${${(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 - } - if (( !OPTS[opt_-q,--quiet] )) && [[ $url != /dev/null ]] { + command cp -vf "$url" "$local_dir/$dirname/$filename" || { + +zi-log "{ehi}ERROR:{error} The file copying has been unsuccessful.{rst}" + retval=4 + } + else + command cp -f "$url" "$local_dir/$dirname/$filename" &> /dev/null || { + +zi-log "{ehi}ERROR:{error} The copying of {file}$filename{error} has been unsuccessful" "${${(M)OPTS[opt_-q,--quiet]:#1}:+, skip the -q/--quiet option for more information}.{rst}" + retval=4 + } + fi + else + rel_url="$(.zinit-realpath "$local_dir/$dirname" "$url")" + url="${rel_url}" + if (( !OPTS[opt_-q,--quiet] )) && [[ $url != /dev/null ]]; then +zi-log "{msg}Linking {file}$filename{msg}{…}{rst}" - command ln -svf "$url" "$local_dir/$dirname/$filename" || \ - { +zi-log "{ehi}ERROR:{error} The file linking has been unsuccessful.{rst}"; retval=4; } - } else { - command ln -sf "$url" "$local_dir/$dirname/$filename" &>/dev/null || \ - { +zi-log "{ehi}ERROR:{error} The link of {file}$filename{error} has been unsuccessful"\ - "${${(M)OPTS[opt_-q,--quiet]:#1}:+, skip the -q/--quiet option for more information}.{rst}"; retval=4; } - } - } + command ln -svf "$url" "$local_dir/$dirname/$filename" || { + +zi-log "{ehi}ERROR:{error} The file linking has been unsuccessful.{rst}" + retval=4 + } + else + command ln -sf "$url" "$local_dir/$dirname/$filename" &> /dev/null || { + +zi-log "{ehi}ERROR:{error} The link of {file}$filename{error} has been unsuccessful" "${${(M)OPTS[opt_-q,--quiet]:#1}:+, skip the -q/--quiet option for more information}.{rst}" + retval=4 + } + fi + fi + } (( retval == 4 )) && { command rmdir "$local_dir/$dirname" 2>/dev/null; return $retval; }