Skip to content

Commit 1fb1e24

Browse files
vladdosterpschmitt
authored andcommitted
fix: zsh impl of realpath to handle macOS BSD realpath
Signed-off-by: Doster, Vladislav <[email protected]>
1 parent 1cb1df6 commit 1fb1e24

File tree

5 files changed

+49
-38
lines changed

5 files changed

+49
-38
lines changed

.gitignore

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,3 @@
1-
*.[aos]
2-
*.bundle
3-
*.dll
4-
*.orig
5-
*.txt
6-
*.zini
71
*.zwc
8-
*deploy*key*
9-
*~
10-
.*.sw?
11-
.project
12-
TAGS
13-
TODO*
14-
\#*
152
doc/zsdoc/data
16-
other
17-
site*/
18-
tags
19-
test/
20-
txt/
21-
zmodules/
22-
tests/_output/
23-
tests/_support/tmp*
24-
.idea
3+
tests/_support/tmp\.*

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ DOC_SRC := $(foreach wrd,$(SRC),../$(wrd))
77
.PHONY: all clean container doc doc/container tags tags/emacs tags/vim test zwc
88

99
clean:
10-
rm -rf *.zwc doc/zsdoc/zinit{'','-additional','-autoload','-install','-side'}.zsh.adoc doc/zsdoc/data/
10+
@rm -rf -- \
11+
*.zwc \
12+
tests/_support/tmp* \
13+
doc/zsdoc/{doc,zinit{'','-additional','-autoload','-install','-side'}.zsh.adoc} \
14+
1115

1216
container:
1317
docker build --tag=ghcr.io/zdharma-continuum/zinit:latest --file=docker/Dockerfile .

doc/zsdoc/zinit-install.zsh.adoc

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ Documentation automatically generated with `zshelldoc'
2424
.zinit-json-get-value
2525
.zinit-json-to-array
2626
.zinit-mirror-using-svn
27+
.zinit-realpath
2728
.zinit-setup-plugin-dir
2829
.zinit-single-line
2930
.zinit-update-snippet
@@ -193,7 +194,7 @@ ____
193194
194195
____
195196

196-
Has 377 line(s). Calls functions:
197+
Has 372 line(s). Calls functions:
197198

198199
.zinit-download-snippet
199200
|-- .zinit-download-file-stdout
@@ -211,10 +212,9 @@ Has 377 line(s). Calls functions:
211212
|   `-- zinit.zsh/.zinit-any-to-user-plugin
212213
|-- .zinit-mirror-using-svn
213214
|-- zinit-side.zsh/.zinit-store-ices
214-
|-- zinit.zsh/+zinit-message
215-
`-- zinit.zsh/is-at-least
215+
`-- zinit.zsh/+zinit-message
216216

217-
Uses feature(s): _is-at-least_, _setopt_, _trap_, _zcompile_
217+
Uses feature(s): _setopt_, _trap_, _zcompile_
218218

219219
Called by:
220220

@@ -458,6 +458,20 @@ Called by:
458458

459459
.zinit-download-snippet
460460

461+
==== .zinit-realpath
462+
463+
____
464+
465+
466+
$1: Initial path
467+
$2: Target path
468+
469+
____
470+
471+
Has 16 line(s). Doesn't call other functions.
472+
473+
Not called by script or any function (may be e.g. a hook, a Zle widget, etc.).
474+
461475
==== .zinit-setup-plugin-dir
462476

463477
____
@@ -541,8 +555,7 @@ Has 76 line(s). Calls functions:
541555
|   |   `-- zinit.zsh/.zinit-any-to-user-plugin
542556
|   |-- .zinit-mirror-using-svn
543557
|   |-- zinit-side.zsh/.zinit-store-ices
544-
|   |-- zinit.zsh/+zinit-message
545-
|   `-- zinit.zsh/is-at-least
558+
|   `-- zinit.zsh/+zinit-message
546559
|-- zinit.zsh/+zinit-message
547560
|-- zinit.zsh/.zinit-get-object-path
548561
`-- zinit.zsh/.zinit-pack-ice

doc/zsdoc/zinit.zsh.adoc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1965,5 +1965,4 @@ Called by:
19651965
:zinit-tmp-subst-autoload
19661966
:zinit-tmp-subst-bindkey
19671967
Script-Body
1968-
zinit-install.zsh/.zinit-download-snippet
19691968

zinit-install.zsh

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,28 @@ builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh" || {
66
builtin print -P "${ZINIT[col-error]}ERROR:%f%b Couldn't find ${ZINIT[col-obj]}zinit-side.zsh%f%b."
77
return 1
88
}
9-
9+
# FUNCTION: .zinit-realpath [[[
10+
#
11+
# $1: Initial path
12+
# $2: Target path
13+
.zinit-realpath () {
14+
[[ $# -ge 1 ]] && [[ $# -le 2 ]] || return 1
15+
local target=${${2:-$1}:a} current=${${${2:+$1}:-$PWD}:a} relative=''
16+
local appendix="${target#/}"
17+
while appendix="${target#${current}/}"
18+
[[ $current != '/' ]] && [[ $appendix = $target ]]
19+
do
20+
if [[ $current = $appendix ]]; then
21+
relative="${relative:-.}"
22+
builtin print -- "${relative#/}"
23+
return 0
24+
fi
25+
current=${current%/*}
26+
relative="$relative${relative:+/}.."
27+
done
28+
relative+=${relative:+${appendix:+/}}${appendix#/}
29+
builtin print -- "$relative"
30+
} # ]]]
1031
# FUNCTION: .zinit-jq-check [[[
1132
# Check if jq is available and outputs an error message with instructions if
1233
# that's not the case
@@ -1198,13 +1219,8 @@ builtin source "${ZINIT[BIN_DIR]}/zinit-side.zsh" || {
11981219
"${${(M)OPTS[opt_-q,--quiet]:#1}:+, skip the -q/--quiet option for more information}.{rst}"; retval=4; }
11991220
}
12001221
} else {
1201-
if (( $+commands[realpath] )) {
1202-
local rpv="$(realpath --version | head -n1 | sed -E 's/realpath (\(.*\))?//g')"
1203-
if is-at-least 8.23 $rpv; then
1204-
rel_url="$(realpath --relative-to="$local_dir/$dirname" "$url")" && \
1205-
{ url="$rel_url" }
1206-
fi
1207-
}
1222+
rel_url="$(.zinit-realpath "$local_dir/$dirname" "$url")" && \
1223+
{ url="$rel_url" }
12081224
if (( !OPTS[opt_-q,--quiet] )) && [[ $url != /dev/null ]] {
12091225
+zinit-message "{msg}Linking {file}$filename{msg}{…}{rst}"
12101226
command ln -svf "$url" "$local_dir/$dirname/$filename" || \

0 commit comments

Comments
 (0)