Skip to content

Commit f9153cb

Browse files
committed
fix: load login shell environment when TERM is unset (#594)
1 parent 19d04bf commit f9153cb

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

editor/editor.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package editor
33
import (
44
"context"
55
"fmt"
6-
"io/ioutil"
6+
"io"
77
"log"
88
"os"
99
"os/exec"
@@ -867,31 +867,34 @@ func (e *Editor) setEnvironmentVariables() {
867867
}
868868

869869
// If the OS is MacOS and the application is launched from an .app
870-
if runtime.GOOS == "darwin" && e.ppid == 1 {
870+
if runtime.GOOS == "darwin" && os.Getenv("TERM") == "" {
871871
shell := os.Getenv("SHELL")
872872
if shell == "" {
873-
shell = os.Getenv("/bin/bash")
873+
shell = "/bin/zsh" // fallback
874874
}
875-
cmd := exec.Command(shell, "-l", "-c", "env", "-i")
876-
// cmd := exec.Command("printenv")
875+
876+
cmd := exec.Command(shell, "-l", "-c", "env")
877877
stdout, err := cmd.StdoutPipe()
878878
if err != nil {
879879
e.putLog(err)
880880
return
881881
}
882+
882883
if err := cmd.Start(); err != nil {
883884
e.putLog(err)
884885
return
885886
}
886-
output, err := ioutil.ReadAll(stdout)
887+
888+
output, err := io.ReadAll(stdout)
889+
stdout.Close()
887890
if err != nil {
888891
e.putLog(err)
889-
stdout.Close()
890892
return
891893
}
892-
for _, b := range strings.Split(string(output), "\n") {
893-
splits := strings.SplitN(b, "=", 2)
894-
if len(splits) > 1 {
894+
895+
for _, line := range strings.Split(string(output), "\n") {
896+
splits := strings.SplitN(line, "=", 2)
897+
if len(splits) == 2 {
895898
_ = os.Setenv(splits[0], splits[1])
896899
}
897900
}

0 commit comments

Comments
 (0)