Skip to content

Commit

Permalink
fix: zsh impl of realpath handles old macOS BSD realpath
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Doster <mvdoster@gmail.com>
  • Loading branch information
vladdoster committed Jun 3, 2023
1 parent 879d889 commit 348f5d4
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 38 deletions.
23 changes: 1 addition & 22 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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\.*
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
Expand Down
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 @@ -193,7 +194,7 @@ ____
____

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

.zinit-download-snippet
|-- .zinit-download-file-stdout
Expand All @@ -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:

Expand Down Expand Up @@ -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

____
Expand Down Expand Up @@ -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
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

32 changes: 24 additions & 8 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 @@ -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" || \
Expand Down

0 comments on commit 348f5d4

Please sign in to comment.