Skip to content

Commit

Permalink
automatically set HOME env var
Browse files Browse the repository at this point in the history
  • Loading branch information
pomdtr committed Dec 20, 2023
1 parent d1b6dc0 commit fb03406
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ func NewHandler() (http.Handler, error) {
}
})

currentUser, err := user.Current()
if err != nil {
return nil, fmt.Errorf("error getting current user: %w", err)
}
ttyMap := make(map[string]*os.File)
r.Get("/pty/{terminalID}", func(w http.ResponseWriter, r *http.Request) {
terminalID := chi.URLParam(r, "terminalID")
Expand Down Expand Up @@ -119,14 +123,8 @@ func NewHandler() (http.Handler, error) {

cmd := exec.Command(profile.Command, profile.Args...)
cmd.Env = append(cmd.Env, "TERM=xterm-256color")
currentUser, err := user.Current()
if err != nil {
log.Printf("failed to get current user: %s", err)
w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
return
}
cmd.Env = append(cmd.Env, fmt.Sprintf("USER=%s", currentUser.Username))
cmd.Env = append(cmd.Env, fmt.Sprintf("HOME=%s", currentUser.HomeDir))

for k, v := range config.Env {
cmd.Env = append(cmd.Env, fmt.Sprintf("%s=%s", k, v))
Expand Down

0 comments on commit fb03406

Please sign in to comment.