Skip to content

Commit e456fe4

Browse files
committed
relaunch in preferred shell
add support for rtx Fixes #945 Fixes #963
1 parent 7ef972d commit e456fe4

File tree

2 files changed

+74
-52
lines changed

2 files changed

+74
-52
lines changed

apps/elixir_ls_utils/priv/launch.sh

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/bin/sh
22
# Actual launcher. This does the hard work of figuring out the best way
33
# to launch the language server or the debugger.
4-
#
54

65
# Running this script is a one-time action per project launch, so we opt for
76
# code simplicity instead of performance. Hence some potentially redundant
@@ -11,37 +10,47 @@
1110

1211
did_relaunch=$1
1312

13+
case "${did_relaunch}" in
14+
"")
15+
# Get the user's preferred shell
16+
preferred_shell=$(basename "$SHELL")
17+
if [ "$preferred_shell" = "bash" ]; then
18+
>&2 echo "Preffered shell is bash, relaunching"
19+
exec "$(which bash)" "$0" relaunch
20+
elif [ "$preferred_shell" = "zsh" ]; then
21+
>&2 echo "Preffered shell is zsh, relaunching"
22+
exec "$(which zsh)" "$0" relaunch
23+
else
24+
>&2 echo "Preffered shell $preferred_shell is not supported, continuing in POSIX shell"
25+
fi
26+
;;
27+
*)
28+
# We have an arg2, so we got relaunched
29+
;;
30+
esac
31+
1432
ASDF_DIR=${ASDF_DIR:-"${HOME}/.asdf"}
1533

1634
asdf_vm="${ASDF_DIR}/asdf.sh"
1735

18-
>&2 echo "Looking for ASDF install in $asdf_vm"
19-
36+
>&2 echo "Looking for ASDF install"
2037
if test -f "${asdf_vm}"
2138
then
22-
# asdf-vm does not support the plain posix shell. Figure out
23-
# which one we need and relaunch ourselves with that.
24-
case "${did_relaunch}" in
25-
"")
26-
if which bash >/dev/null
27-
then
28-
>&2 echo "ASDF found, relaunching in bash shell"
29-
exec "$(which bash)" "$0" relaunch
30-
elif which zsh >/dev/null
31-
then
32-
>&2 echo "ASDF found, relaunching in zsh shell"
33-
exec "$(which zsh)" "$0" relaunch
34-
else
35-
>&2 echo "ASDF found, but could not locate ASDF compatible shell"
36-
fi
37-
;;
38-
*)
39-
# We have an arg2, so we got relaunched. Therefore, we're running in a
40-
# shell that supports asdf-vm.
41-
>&2 echo "Sourcing ASDF"
42-
. "${asdf_vm}"
43-
;;
44-
esac
39+
>&2 echo "ASDF install found in $asdf_vm, sourcing"
40+
# shellcheck disable=SC1090
41+
. "${asdf_vm}"
42+
else
43+
>&2 echo "ASDF not found"
44+
>&2 echo "Looking for rtx executable"
45+
46+
if which rtx >/dev/null
47+
then
48+
>&2 echo "rtx executable found in $(which rtx), activating"
49+
preferred_shell=$(basename "$SHELL")
50+
eval "$($(which rtx) activate "$preferred_shell")"
51+
else
52+
>&2 echo "rtx not found"
53+
fi
4554
fi
4655

4756
# In case that people want to tweak the path, which Elixir to use, or
@@ -53,6 +62,7 @@ els_setup="${XDG_CONFIG_HOME:-$HOME/.config}/elixir_ls/setup.sh"
5362
if test -f "${els_setup}"
5463
then
5564
>&2 echo "Running setup script $els_setup"
65+
# shellcheck disable=SC1090
5666
. "${els_setup}"
5767
fi
5868

@@ -79,4 +89,5 @@ fi
7989

8090
export ERL_LIBS="$SCRIPTPATH:$ERL_LIBS"
8191

92+
# shellcheck disable=SC2086
8293
exec elixir $ELS_ELIXIR_OPTS --erl "-kernel standard_io_encoding latin1 +sbwt none +sbwtdcpu none +sbwtdio none $ELS_ERL_OPTS" -e "$ELS_SCRIPT"

scripts/launch.sh

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/bin/sh
22
# Actual launcher. This does the hard work of figuring out the best way
33
# to launch the language server or the debugger.
4-
#
54

65
# Running this script is a one-time action per project launch, so we opt for
76
# code simplicity instead of performance. Hence some potentially redundant
@@ -11,37 +10,47 @@
1110

1211
did_relaunch=$1
1312

13+
case "${did_relaunch}" in
14+
"")
15+
# Get the user's preferred shell
16+
preferred_shell=$(basename "$SHELL")
17+
if [ "$preferred_shell" = "bash" ]; then
18+
>&2 echo "Preffered shell is bash, relaunching"
19+
exec "$(which bash)" "$0" relaunch
20+
elif [ "$preferred_shell" = "zsh" ]; then
21+
>&2 echo "Preffered shell is zsh, relaunching"
22+
exec "$(which zsh)" "$0" relaunch
23+
else
24+
>&2 echo "Preffered shell $preferred_shell is not supported, continuing in POSIX shell"
25+
fi
26+
;;
27+
*)
28+
# We have an arg2, so we got relaunched
29+
;;
30+
esac
31+
1432
ASDF_DIR=${ASDF_DIR:-"${HOME}/.asdf"}
1533

1634
asdf_vm="${ASDF_DIR}/asdf.sh"
1735

18-
>&2 echo "Looking for ASDF install in $asdf_vm"
19-
36+
>&2 echo "Looking for ASDF install"
2037
if test -f "${asdf_vm}"
2138
then
22-
# asdf-vm does not support the plain posix shell. Figure out
23-
# which one we need and relaunch ourselves with that.
24-
case "${did_relaunch}" in
25-
"")
26-
if which bash >/dev/null
27-
then
28-
>&2 echo "ASDF found, relaunching in bash shell"
29-
exec "$(which bash)" "$0" relaunch
30-
elif which zsh >/dev/null
31-
then
32-
>&2 echo "ASDF found, relaunching in zsh shell"
33-
exec "$(which zsh)" "$0" relaunch
34-
else
35-
>&2 echo "ASDF found, but could not locate ASDF compatible shell"
36-
fi
37-
;;
38-
*)
39-
# We have an arg2, so we got relaunched. Therefore, we're running in a
40-
# shell that supports asdf-vm.
41-
>&2 echo "Sourcing ASDF"
42-
. "${asdf_vm}"
43-
;;
44-
esac
39+
>&2 echo "ASDF install found in $asdf_vm, sourcing"
40+
# shellcheck disable=SC1090
41+
. "${asdf_vm}"
42+
else
43+
>&2 echo "ASDF not found"
44+
>&2 echo "Looking for rtx executable"
45+
46+
if which rtx >/dev/null
47+
then
48+
>&2 echo "rtx executable found in $(which rtx), activating"
49+
preferred_shell=$(basename "$SHELL")
50+
eval "$($(which rtx) activate "$preferred_shell")"
51+
else
52+
>&2 echo "rtx not found"
53+
fi
4554
fi
4655

4756
# In case that people want to tweak the path, which Elixir to use, or
@@ -53,6 +62,7 @@ els_setup="${XDG_CONFIG_HOME:-$HOME/.config}/elixir_ls/setup.sh"
5362
if test -f "${els_setup}"
5463
then
5564
>&2 echo "Running setup script $els_setup"
65+
# shellcheck disable=SC1090
5666
. "${els_setup}"
5767
fi
5868

@@ -82,4 +92,5 @@ export MIX_ENV=prod
8292
# we need to make sure it doesn't interfere with LSP/DAP
8393
echo "" | elixir "$SCRIPTPATH/quiet_install.exs" >/dev/null || exit 1
8494

95+
# shellcheck disable=SC2086
8596
exec elixir $ELS_ELIXIR_OPTS --erl "-kernel standard_io_encoding latin1 +sbwt none +sbwtdcpu none +sbwtdio none $ELS_ERL_OPTS" "$SCRIPTPATH/launch.exs"

0 commit comments

Comments
 (0)