Skip to content

Commit

Permalink
relaunch in preferred shell
Browse files Browse the repository at this point in the history
add support for rtx
Fixes #945
Fixes #963
  • Loading branch information
lukaszsamson committed Aug 18, 2023
1 parent 7ef972d commit e456fe4
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 52 deletions.
63 changes: 37 additions & 26 deletions apps/elixir_ls_utils/priv/launch.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/sh
# Actual launcher. This does the hard work of figuring out the best way
# to launch the language server or the debugger.
#

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

did_relaunch=$1

case "${did_relaunch}" in
"")
# Get the user's preferred shell
preferred_shell=$(basename "$SHELL")
if [ "$preferred_shell" = "bash" ]; then
>&2 echo "Preffered shell is bash, relaunching"
exec "$(which bash)" "$0" relaunch
elif [ "$preferred_shell" = "zsh" ]; then
>&2 echo "Preffered shell is zsh, relaunching"
exec "$(which zsh)" "$0" relaunch
else
>&2 echo "Preffered shell $preferred_shell is not supported, continuing in POSIX shell"
fi
;;
*)
# We have an arg2, so we got relaunched
;;
esac

ASDF_DIR=${ASDF_DIR:-"${HOME}/.asdf"}

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

>&2 echo "Looking for ASDF install in $asdf_vm"

>&2 echo "Looking for ASDF install"
if test -f "${asdf_vm}"
then
# asdf-vm does not support the plain posix shell. Figure out
# which one we need and relaunch ourselves with that.
case "${did_relaunch}" in
"")
if which bash >/dev/null
then
>&2 echo "ASDF found, relaunching in bash shell"
exec "$(which bash)" "$0" relaunch
elif which zsh >/dev/null
then
>&2 echo "ASDF found, relaunching in zsh shell"
exec "$(which zsh)" "$0" relaunch
else
>&2 echo "ASDF found, but could not locate ASDF compatible shell"
fi
;;
*)
# We have an arg2, so we got relaunched. Therefore, we're running in a
# shell that supports asdf-vm.
>&2 echo "Sourcing ASDF"
. "${asdf_vm}"
;;
esac
>&2 echo "ASDF install found in $asdf_vm, sourcing"
# shellcheck disable=SC1090
. "${asdf_vm}"
else
>&2 echo "ASDF not found"
>&2 echo "Looking for rtx executable"

if which rtx >/dev/null
then
>&2 echo "rtx executable found in $(which rtx), activating"
preferred_shell=$(basename "$SHELL")
eval "$($(which rtx) activate "$preferred_shell")"
else
>&2 echo "rtx not found"
fi
fi

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

Expand All @@ -79,4 +89,5 @@ fi

export ERL_LIBS="$SCRIPTPATH:$ERL_LIBS"

# shellcheck disable=SC2086
exec elixir $ELS_ELIXIR_OPTS --erl "-kernel standard_io_encoding latin1 +sbwt none +sbwtdcpu none +sbwtdio none $ELS_ERL_OPTS" -e "$ELS_SCRIPT"
63 changes: 37 additions & 26 deletions scripts/launch.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/bin/sh
# Actual launcher. This does the hard work of figuring out the best way
# to launch the language server or the debugger.
#

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

did_relaunch=$1

case "${did_relaunch}" in
"")
# Get the user's preferred shell
preferred_shell=$(basename "$SHELL")
if [ "$preferred_shell" = "bash" ]; then
>&2 echo "Preffered shell is bash, relaunching"
exec "$(which bash)" "$0" relaunch
elif [ "$preferred_shell" = "zsh" ]; then
>&2 echo "Preffered shell is zsh, relaunching"
exec "$(which zsh)" "$0" relaunch
else
>&2 echo "Preffered shell $preferred_shell is not supported, continuing in POSIX shell"
fi
;;
*)
# We have an arg2, so we got relaunched
;;
esac

ASDF_DIR=${ASDF_DIR:-"${HOME}/.asdf"}

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

>&2 echo "Looking for ASDF install in $asdf_vm"

>&2 echo "Looking for ASDF install"
if test -f "${asdf_vm}"
then
# asdf-vm does not support the plain posix shell. Figure out
# which one we need and relaunch ourselves with that.
case "${did_relaunch}" in
"")
if which bash >/dev/null
then
>&2 echo "ASDF found, relaunching in bash shell"
exec "$(which bash)" "$0" relaunch
elif which zsh >/dev/null
then
>&2 echo "ASDF found, relaunching in zsh shell"
exec "$(which zsh)" "$0" relaunch
else
>&2 echo "ASDF found, but could not locate ASDF compatible shell"
fi
;;
*)
# We have an arg2, so we got relaunched. Therefore, we're running in a
# shell that supports asdf-vm.
>&2 echo "Sourcing ASDF"
. "${asdf_vm}"
;;
esac
>&2 echo "ASDF install found in $asdf_vm, sourcing"
# shellcheck disable=SC1090
. "${asdf_vm}"
else
>&2 echo "ASDF not found"
>&2 echo "Looking for rtx executable"

if which rtx >/dev/null
then
>&2 echo "rtx executable found in $(which rtx), activating"
preferred_shell=$(basename "$SHELL")
eval "$($(which rtx) activate "$preferred_shell")"
else
>&2 echo "rtx not found"
fi
fi

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

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

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

0 comments on commit e456fe4

Please sign in to comment.