Detect fish shell

Signed-off-by: Jean-Laurent de Morlhon <jeanlaurent@morlhon.net>
This commit is contained in:
Jean-Laurent de Morlhon 2015-12-17 16:05:13 +01:00
parent 32795c9d1f
commit c07067c7e4
2 changed files with 23 additions and 0 deletions

View File

@ -261,5 +261,9 @@ func detectShell() (string, error) {
return "", ErrUnknownShell
}
if os.Getenv("__fish_bin_dir") != "" {
return "fish", nil
}
return shell, nil
}

View File

@ -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)
}