diff --git a/Gopkg.lock b/Gopkg.lock index e7b16ba..ad51f85 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -137,7 +137,7 @@ branch = "master" name = "github.com/riywo/loginshell" packages = ["."] - revision = "5da3acff02554cee5e8ccb4651cc5a4072f41790" + revision = "c2f4167b23039c6289b5a488080176426ec5dad9" [[projects]] name = "github.com/stretchr/testify" diff --git a/vendor/github.com/riywo/loginshell/loginshell.go b/vendor/github.com/riywo/loginshell/loginshell.go index d8d256d..f7d71ea 100644 --- a/vendor/github.com/riywo/loginshell/loginshell.go +++ b/vendor/github.com/riywo/loginshell/loginshell.go @@ -17,15 +17,29 @@ func Shell() (string, error) { return LinuxShell() case "darwin": return DarwinShell() + case "windows": + return WindowsShell() } return "", errors.New("Undefined GOOS: " + runtime.GOOS) } +func WindowsShell() (string, error) { + consoleApp := os.Getenv("COMSPEC") + if consoleApp == "" { + consoleApp = "cmd.exe" + } + return consoleApp, nil +} + func LinuxShell() (string, error) { user, err := user.Current() - if err != nil { return "", err } + if err != nil { + return "", err + } out, err := exec.Command("getent", "passwd", user.Uid).Output() - if err != nil { return "", err } + if err != nil { + return "", err + } ent := strings.Split(strings.TrimSuffix(string(out), "\n"), ":") return ent[6], nil @@ -34,11 +48,15 @@ func LinuxShell() (string, error) { func DarwinShell() (string, error) { dir := "Local/Default/Users/" + os.Getenv("USER") out, err := exec.Command("dscl", "localhost", "-read", dir, "UserShell").Output() - if err != nil { return "", err } + if err != nil { + return "", err + } re := regexp.MustCompile("UserShell: (/[^ ]+)\n") matched := re.FindStringSubmatch(string(out)) shell := matched[1] - if shell == "" { return "", errors.New(fmt.Sprintf("Invalid output: %s", string(out))) } + if shell == "" { + return "", errors.New(fmt.Sprintf("Invalid output: %s", string(out))) + } return shell, nil } diff --git a/vendor/github.com/riywo/loginshell/loginshell_test.go b/vendor/github.com/riywo/loginshell/loginshell_test.go index c7f169c..78f0610 100644 --- a/vendor/github.com/riywo/loginshell/loginshell_test.go +++ b/vendor/github.com/riywo/loginshell/loginshell_test.go @@ -4,6 +4,7 @@ import ( "testing" "os" "fmt" + "runtime" ) func TestShell(t *testing.T) { @@ -12,8 +13,14 @@ func TestShell(t *testing.T) { t.Error(err) } - currentShell := os.Getenv("SHELL") - if shell != currentShell { - t.Error(fmt.Sprintf("Output: %s, Current login shell: %s", shell, currentShell)) + if runtime.GOOS == "windows" { + if shell == "" { + t.Error("Output is empty!") + } + } else { + currentShell := os.Getenv("SHELL") + if shell != currentShell { + t.Error(fmt.Sprintf("Output: %s, Current login shell: %s", shell, currentShell)) + } } }