Skip to content

Commit

Permalink
fix: need to forward some env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
bomgar committed Oct 18, 2024
1 parent 5574bf9 commit 3c7904a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
27 changes: 26 additions & 1 deletion nvimwrapper/nvim.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log/slog"
"maps"
"os"
"os/exec"
"strings"
"sync"
Expand Down Expand Up @@ -63,9 +64,25 @@ func (r NvimResult) Col() int {
return r.CursorPosition[1]
}

func forwardEnv() []string {

forwardVars := []string{"DOCKER_HOST"}

env := []string{}

for _, varName := range forwardVars {
varValue := os.Getenv(varName)
env = append(env, fmt.Sprintf("DOCKER_HOST=%s", varValue))
}
slog.Info("Spawn with env", "env", env)

return env

}

func spawnExternal(cmdline string, args []string) (*nvim.Nvim, error) {
cmdCtx := exec.CommandContext(context.Background(), cmdline, args...)
cmdCtx.Env = []string{}
cmdCtx.Env = forwardEnv()
cmdCtx.Dir = ""

inw, err := cmdCtx.StdinPipe()
Expand All @@ -79,6 +96,14 @@ func spawnExternal(cmdline string, args []string) (*nvim.Nvim, error) {
return nil, err
}

// TODO: log this
// errr, err := cmdCtx.StderrPipe()
// if err != nil {
// return nil, err
// }
//
// go io.Copy(os.Stdout, errr)

err = cmdCtx.Start()
if err != nil {
return nil, err
Expand Down
5 changes: 5 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log/slog"
"net/http"
"os"
"time"

"github.com/brocode/neoweb/components"
"github.com/brocode/neoweb/key"
Expand All @@ -26,6 +27,10 @@ func NewServer() *Server {
nvimWrapper, err := nvimwrapper.Spawn()
if err != nil {
slog.Error("Failed to spawn neovim", "Error", err)

// TODO this sleep is so that async stuff can print errors.
// Need to remove the entire nvim spawn handling anyway
time.Sleep(1 * time.Second)
os.Exit(1)
}

Expand Down

0 comments on commit 3c7904a

Please sign in to comment.