@@ -3,7 +3,7 @@ package editor
33import (
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 }
@@ -1100,11 +1103,18 @@ func (e *Editor) setWindowSizeFromOpts() {
11001103func (e * Editor ) setWindowSize (s string ) (int , int ) {
11011104 var width , height int
11021105 var err error
1103- width , err = strconv .Atoi (strings .SplitN (s , "x" , 2 )[0 ])
1106+
1107+ parsed_s := strings .SplitN (s , "x" , 2 )
1108+ if len (parsed_s ) != 2 {
1109+ // TODO: Error message to user?
1110+ return 40 , 30
1111+ }
1112+
1113+ width , err = strconv .Atoi (parsed_s [0 ])
11041114 if err != nil || width < 40 {
11051115 width = 40
11061116 }
1107- height , err = strconv .Atoi (strings . SplitN ( s , "x" , 2 ) [1 ])
1117+ height , err = strconv .Atoi (parsed_s [1 ])
11081118 if err != nil || height < 30 {
11091119 height = 30
11101120 }
0 commit comments