Skip to content

Commit 4809ea3

Browse files
committed
Add Zsh support to Spin environment file
The previous commit made it possible to source the Spin environment file from a Bash script, but we also need to be able to source it directly from a Zsh command line. `$BASH_SOURCE` isn’t supported by Zsh so the current solution doesn’t work for the latter purpose. This commit uses shell parameter expansion syntax [0,1] to supply a Zsh-compatible equivalent if `$BASH_SOURCE` isn’t set. The expression `${(%):-%x}` in Zsh does the same job as `$BASH_SOURCE` in Bash: `(%)` is a parameter expansion flag [2] which enables prompt sequence expansion [3] in what follows, and `%x` is the prompt sequence for “the name of the file containing the source code currently being executed” [4]. [0] https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html [1] https://zsh.sourceforge.io/Doc/Release/Expansion.html#Parameter-Expansion [2] https://zsh.sourceforge.io/Doc/Release/Expansion.html#index-parameter-expansion-flags [3] https://zsh.sourceforge.io/Doc/Release/Prompt-Expansion.html [4] https://zsh.sourceforge.io/Doc/Release/Prompt-Expansion.html#Shell-state
1 parent 706218d commit 4809ea3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

.spin/bin/env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
SCRIPT_PATH=$(dirname "$BASH_SOURCE[0]")
3+
SCRIPT_PATH=$(dirname "${BASH_SOURCE[0]:-${(%):-%x}}")
44
SCRIPT_PATH=$(cd "$SCRIPT_PATH" && pwd)
55
TRUFFLERUBY_DIR=$SCRIPT_PATH/../..
66
export JT_ENV=jvm-ce

0 commit comments

Comments
 (0)