Skip to content

Commit

Permalink
set user env var
Browse files Browse the repository at this point in the history
  • Loading branch information
pomdtr committed Dec 18, 2023
1 parent febd7e7 commit d1b6dc0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"
"os"
"os/exec"
"os/user"
"path/filepath"
"strconv"
"strings"
Expand Down Expand Up @@ -118,6 +119,15 @@ 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))

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

0 comments on commit d1b6dc0

Please sign in to comment.