Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion apps/expert/lib/expert/port.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,16 @@ defmodule Expert.Port do
# managed programs.
shell = System.get_env("SHELL")

{path, 0} = System.cmd(shell, ["-i", "-l", "-c", "cd #{root_path} && echo $PATH"])
# Ideally, it should contain the path to shell (e.g. `/usr/bin/fish`),
# but it might contain only the name of the shell (e.g. `fish`).
is_fish? = String.contains?(shell, "fish")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can use Path.basename/1 here instead


# Fish uses space-separated PATH, so we use the built-in `string join` command
# to join the entries with colons and have a standard colon-separated PATH output
# as in bash, which is expected by `:os.find_executable/2`.
path_command = if is_fish?, do: "string join ':' $PATH", else: "echo $PATH"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: we prefer something like fish_shell?, is_x? mixes both naming conventions for guards and booleans


{path, 0} = System.cmd(shell, ["-i", "-l", "-c", "cd #{root_path} && #{path_command}"])

case :os.find_executable(~c"elixir", to_charlist(path)) do
false ->
Expand Down
Loading