@@ -34,14 +34,8 @@ defmodule Expert.Port do
3434 def elixir_executable ( % Project { } = project ) do
3535 root_path = Project . root_path ( project )
3636
37- # We run a shell in interactive mode to populate the PATH with the right value
38- # at the project root. Otherwise, we either can't find an elixir executable,
39- # we use the wrong version if the user uses a version manager like asdf/mise,
40- # or we get an incomplete PATH not including erl or any other version manager
41- # managed programs.
4237 shell = System . get_env ( "SHELL" )
43-
44- { path , 0 } = System . cmd ( shell , [ "-i" , "-l" , "-c" , "cd #{ root_path } && echo $PATH" ] )
38+ path = path_env_at_directory ( root_path , shell )
4539
4640 case :os . find_executable ( ~c" elixir" , to_charlist ( path ) ) do
4741 false ->
@@ -63,6 +57,31 @@ defmodule Expert.Port do
6357 end
6458 end
6559
60+ defp path_env_at_directory ( directory , shell ) do
61+ # We run a shell in interactive mode to populate the PATH with the right value
62+ # at the project root. Otherwise, we either can't find an elixir executable,
63+ # we use the wrong version if the user uses a version manager like asdf/mise,
64+ # or we get an incomplete PATH not including erl or any other version manager
65+ # managed programs.
66+
67+ case Path . basename ( shell ) do
68+ # Ideally, it should contain the path to shell (e.g. `/usr/bin/fish`),
69+ # but it might contain only the name of the shell (e.g. `fish`).
70+ "fish" ->
71+ # Fish uses space-separated PATH, so we use the built-in `string join` command
72+ # to join the entries with colons and have a standard colon-separated PATH output
73+ # as in bash, which is expected by `:os.find_executable/2`.
74+ { path , 0 } =
75+ System . cmd ( shell , [ "-i" , "-l" , "-c" , "cd #{ directory } && string join ':' $PATH" ] )
76+
77+ path
78+
79+ _ ->
80+ { path , 0 } = System . cmd ( shell , [ "-i" , "-l" , "-c" , "cd #{ directory } && echo $PATH" ] )
81+ path
82+ end
83+ end
84+
6685 @ doc """
6786 Launches an executable in the project context via a port.
6887 """
0 commit comments