Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: zsh impl of realpath handles old macOS BSD realpath #521

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions doc/zsdoc/zinit-install.zsh.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -192,7 +193,7 @@ ____

____

Has 377 line(s). Calls functions:
Has 380 line(s). Calls functions:

.zinit-download-snippet
|-- .zinit-download-file-stdout
Expand All @@ -210,10 +211,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:

Expand Down Expand Up @@ -456,6 +456,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

____
Expand Down Expand Up @@ -539,8 +553,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
Expand Down
1 change: 0 additions & 1 deletion doc/zsdoc/zinit.zsh.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1965,5 +1965,4 @@ Called by:
:zinit-tmp-subst-autoload
:zinit-tmp-subst-bindkey
Script-Body
zinit-install.zsh/.zinit-download-snippet

3 changes: 3 additions & 0 deletions tests/commands.zunit
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
assert $output contains 'Already up-to-date.'
assert $state equals 0
}

@test 'set-debug' {
ZINIT+=(DEBUG 'true')
run +zi-log -n '{dbg} message'
Expand All @@ -73,3 +74,5 @@
run +zi-log -n '{m} message'
assert $output contains 'message'; assert $state equals 0
}

# vim:ft=zsh:sw=2:sts=2:et:foldmarker={,}:foldmethod=marker
78 changes: 51 additions & 27 deletions zinit-install.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1193,34 +1214,37 @@ 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
}
pschmitt marked this conversation as resolved.
Show resolved Hide resolved
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; }
Expand Down
Loading