From e71b1c80b4af7acb0711414f32d161699812a2cf Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Thu, 10 Feb 2022 17:52:02 -0800 Subject: [PATCH] Skip Shell check on Windows (#3973) Fixes `mc: Failed to enable autocompletion. Cannot determine shell-type and SHELL environment variable found: exit status 1.` on Windows. --- cmd/main.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index e9a8475a..566a95b8 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -302,18 +302,19 @@ func initMC() { func getShellName() (string, bool) { shellName := os.Getenv("SHELL") - if shellName == "" { - ppid := os.Getppid() - cmd := exec.Command("ps", "-p", strconv.Itoa(ppid), "-o", "comm=") - ppName, err := cmd.Output() - if err != nil { - fatalIf(probe.NewError(err), "Failed to enable autocompletion. Cannot determine shell type and"+ - "no SHELL environment variable found") - } - shellName = strings.TrimSpace(string(ppName)) - return strings.ToLower(filepath.Base(shellName)), false + if shellName != "" || runtime.GOOS == "windows" { + return strings.ToLower(filepath.Base(shellName)), true } - return strings.ToLower(filepath.Base(shellName)), true + + ppid := os.Getppid() + cmd := exec.Command("ps", "-p", strconv.Itoa(ppid), "-o", "comm=") + ppName, err := cmd.Output() + if err != nil { + fatalIf(probe.NewError(err), "Failed to enable autocompletion. Cannot determine shell type and "+ + "no SHELL environment variable found") + } + shellName = strings.TrimSpace(string(ppName)) + return strings.ToLower(filepath.Base(shellName)), false } func installAutoCompletion() {