diff --git a/commands/env.go b/commands/env.go index 9663fb7f25..d1c052266d 100644 --- a/commands/env.go +++ b/commands/env.go @@ -261,5 +261,9 @@ func detectShell() (string, error) { return "", ErrUnknownShell } + if os.Getenv("__fish_bin_dir") != "" { + return "fish", nil + } + return shell, nil } diff --git a/commands/env_test.go b/commands/env_test.go index 9989d2ca4b..f3c13a3aeb 100644 --- a/commands/env_test.go +++ b/commands/env_test.go @@ -547,3 +547,22 @@ func TestShellCfgUnset(t *testing.T) { os.Setenv(test.noProxyVar, "") } } + +func TestDetectBash(t *testing.T) { + original_shell := os.Getenv("SHELL") + os.Setenv("SHELL", "/bin/bash") + defer os.Setenv("SHELL", original_shell) + shell, _ := detectShell() + assert.Equal(t, "bash", shell) +} + +func TestDetectFish(t *testing.T) { + original_shell := os.Getenv("SHELL") + os.Setenv("SHELL", "/bin/bash") + defer os.Setenv("SHELL", original_shell) + original_fishdir := os.Getenv("__fish_bin_dir") + os.Setenv("__fish_bin_dir", "/usr/local/Cellar/fish/2.2.0/bin") + defer os.Setenv("__fish_bin_dir", original_fishdir) + shell, _ := detectShell() + assert.Equal(t, "fish", shell) +}