Skip to content

Commit 79718bc

Browse files
committed
split ELS_ELIXIR_OPTS
Fixes #966
1 parent e456fe4 commit 79718bc

File tree

2 files changed

+62
-10
lines changed

2 files changed

+62
-10
lines changed

apps/elixir_ls_utils/priv/launch.sh

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010

1111
did_relaunch=$1
1212

13+
# Get the user's preferred shell
14+
preferred_shell=$(basename "$SHELL")
15+
1316
case "${did_relaunch}" in
1417
"")
15-
# Get the user's preferred shell
16-
preferred_shell=$(basename "$SHELL")
1718
if [ "$preferred_shell" = "bash" ]; then
1819
>&2 echo "Preffered shell is bash, relaunching"
1920
exec "$(which bash)" "$0" relaunch
@@ -46,7 +47,6 @@ else
4647
if which rtx >/dev/null
4748
then
4849
>&2 echo "rtx executable found in $(which rtx), activating"
49-
preferred_shell=$(basename "$SHELL")
5050
eval "$($(which rtx) activate "$preferred_shell")"
5151
else
5252
>&2 echo "rtx not found"
@@ -89,5 +89,31 @@ fi
8989

9090
export ERL_LIBS="$SCRIPTPATH:$ERL_LIBS"
9191

92-
# shellcheck disable=SC2086
93-
exec elixir $ELS_ELIXIR_OPTS --erl "-kernel standard_io_encoding latin1 +sbwt none +sbwtdcpu none +sbwtdio none $ELS_ERL_OPTS" -e "$ELS_SCRIPT"
92+
default_erl_opts="-kernel standard_io_encoding latin1 +sbwt none +sbwtdcpu none +sbwtdio none"
93+
94+
if [ "$preferred_shell" = "bash" ]; then
95+
# we need to make sure ELS_ELIXIR_OPTS gets splitted by word
96+
# parse it as bash array
97+
# shellcheck disable=SC3045
98+
# shellcheck disable=SC3011
99+
IFS=' ' read -ra elixir_opts <<< "$ELS_ELIXIR_OPTS"
100+
# shellcheck disable=SC3054
101+
# shellcheck disable=SC2068
102+
exec elixir ${elixir_opts[@]} --erl "$default_erl_opts $ELS_ERL_OPTS" -e "$ELS_SCRIPT"
103+
elif [ "$preferred_shell" = "zsh" ]; then
104+
# we need to make sure ELS_ELIXIR_OPTS gets splitted by word
105+
# parse it as zsh array
106+
# shellcheck disable=SC3030
107+
# shellcheck disable=SC2296
108+
elixir_opts=("${(z)ELS_ELIXIR_OPTS}")
109+
# shellcheck disable=SC2128
110+
# shellcheck disable=SC2086
111+
exec elixir $elixir_opts --erl "$default_erl_opts $ELS_ERL_OPTS" -e "$ELS_SCRIPT"
112+
else
113+
if [ -z "$ELS_ELIXIR_OPTS" ]
114+
then
115+
# in posix shell does not support arrays
116+
>&2 echo "ELS_ELIXIR_OPTS is not supported in current shell"
117+
fi
118+
exec elixir --erl "$default_erl_opts $ELS_ERL_OPTS" -e "$ELS_SCRIPT"
119+
fi

scripts/launch.sh

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010

1111
did_relaunch=$1
1212

13+
# Get the user's preferred shell
14+
preferred_shell=$(basename "$SHELL")
15+
1316
case "${did_relaunch}" in
1417
"")
15-
# Get the user's preferred shell
16-
preferred_shell=$(basename "$SHELL")
1718
if [ "$preferred_shell" = "bash" ]; then
1819
>&2 echo "Preffered shell is bash, relaunching"
1920
exec "$(which bash)" "$0" relaunch
@@ -46,7 +47,6 @@ else
4647
if which rtx >/dev/null
4748
then
4849
>&2 echo "rtx executable found in $(which rtx), activating"
49-
preferred_shell=$(basename "$SHELL")
5050
eval "$($(which rtx) activate "$preferred_shell")"
5151
else
5252
>&2 echo "rtx not found"
@@ -92,5 +92,31 @@ export MIX_ENV=prod
9292
# we need to make sure it doesn't interfere with LSP/DAP
9393
echo "" | elixir "$SCRIPTPATH/quiet_install.exs" >/dev/null || exit 1
9494

95-
# shellcheck disable=SC2086
96-
exec elixir $ELS_ELIXIR_OPTS --erl "-kernel standard_io_encoding latin1 +sbwt none +sbwtdcpu none +sbwtdio none $ELS_ERL_OPTS" "$SCRIPTPATH/launch.exs"
95+
default_erl_opts="-kernel standard_io_encoding latin1 +sbwt none +sbwtdcpu none +sbwtdio none"
96+
97+
if [ "$preferred_shell" = "bash" ]; then
98+
# we need to make sure ELS_ELIXIR_OPTS gets splitted by word
99+
# parse it as bash array
100+
# shellcheck disable=SC3045
101+
# shellcheck disable=SC3011
102+
IFS=' ' read -ra elixir_opts <<< "$ELS_ELIXIR_OPTS"
103+
# shellcheck disable=SC3054
104+
# shellcheck disable=SC2068
105+
exec elixir ${elixir_opts[@]} --erl "$default_erl_opts $ELS_ERL_OPTS" "$SCRIPTPATH/launch.exs"
106+
elif [ "$preferred_shell" = "zsh" ]; then
107+
# we need to make sure ELS_ELIXIR_OPTS gets splitted by word
108+
# parse it as zsh array
109+
# shellcheck disable=SC3030
110+
# shellcheck disable=SC2296
111+
elixir_opts=("${(z)ELS_ELIXIR_OPTS}")
112+
# shellcheck disable=SC2128
113+
# shellcheck disable=SC2086
114+
exec elixir $elixir_opts --erl "$default_erl_opts $ELS_ERL_OPTS" "$SCRIPTPATH/launch.exs"
115+
else
116+
if [ -z "$ELS_ELIXIR_OPTS" ]
117+
then
118+
# in posix shell does not support arrays
119+
>&2 echo "ELS_ELIXIR_OPTS is not supported in current shell"
120+
fi
121+
exec elixir --erl "$default_erl_opts $ELS_ERL_OPTS" "$SCRIPTPATH/launch.exs"
122+
fi

0 commit comments

Comments
 (0)