From c07067c7e4e08a449bbe8165161e65588b54c09d Mon Sep 17 00:00:00 2001 From: Jean-Laurent de Morlhon Date: Thu, 17 Dec 2015 16:05:13 +0100 Subject: [PATCH] Detect fish shell Signed-off-by: Jean-Laurent de Morlhon --- commands/env.go | 4 ++++ commands/env_test.go | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) 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) +}