From 0eedb71d6ce44c5a78016c2d823b3bedd51daaa0 Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Sun, 17 Mar 2019 19:52:34 +0300 Subject: [PATCH] export permanent env vars on startup Related #134 --- app.go | 21 ++------------------- main.go | 19 +++++++++++++++++++ os.go | 2 ++ os_windows.go | 2 ++ 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/app.go b/app.go index d63dee0a..ac680aef 100644 --- a/app.go +++ b/app.go @@ -8,7 +8,6 @@ import ( "os" "os/exec" "path/filepath" - "strconv" "strings" "time" ) @@ -283,7 +282,7 @@ func (app *app) loop() { } } -func (app *app) exportVars() { +func (app *app) exportFiles() { var envFile string if f, err := app.nav.currFile(); err == nil { envFile = f.path @@ -301,22 +300,6 @@ func (app *app) exportVars() { } else { os.Setenv("fx", envFiles) } - - os.Setenv("id", strconv.Itoa(gClientID)) - - os.Setenv("OPENER", envOpener) - os.Setenv("EDITOR", envEditor) - os.Setenv("PAGER", envPager) - os.Setenv("SHELL", envShell) - - level, err := strconv.Atoi(envLevel) - if err != nil { - log.Printf("reading lf level: %s", err) - } - - level++ - - os.Setenv("LF_LEVEL", strconv.Itoa(level)) } func waitKey() error { @@ -341,7 +324,7 @@ func waitKey() error { // ! Yes No Yes Yes Yes Pause and then resume // & No Yes No No No Do nothing func (app *app) runShell(s string, args []string, prefix string) { - app.exportVars() + app.exportFiles() cmd := shellCommand(s, args) diff --git a/main.go b/main.go index a2298f4b..1cb4c81e 100644 --- a/main.go +++ b/main.go @@ -9,6 +9,7 @@ import ( "path/filepath" "runtime" "runtime/pprof" + "strconv" ) var ( @@ -42,6 +43,24 @@ func init() { } } +func exportEnvVars() { + os.Setenv("id", strconv.Itoa(gClientID)) + + os.Setenv("OPENER", envOpener) + os.Setenv("EDITOR", envEditor) + os.Setenv("PAGER", envPager) + os.Setenv("SHELL", envShell) + + level, err := strconv.Atoi(envLevel) + if err != nil { + log.Printf("reading lf level: %s", err) + } + + level++ + + os.Setenv("LF_LEVEL", strconv.Itoa(level)) +} + func startServer() { cmd := detachedCommand(os.Args[0], "-server") if err := cmd.Start(); err != nil { diff --git a/os.go b/os.go index 1fc896de..43a7d8fd 100644 --- a/os.go +++ b/os.go @@ -84,6 +84,8 @@ func init() { gHistoryPath = filepath.Join(data, "lf", "history") gDefaultSocketPath = filepath.Join(os.TempDir(), fmt.Sprintf("lf.%s.sock", gUser.Username)) + + exportEnvVars() } func detachedCommand(name string, arg ...string) *exec.Cmd { diff --git a/os_windows.go b/os_windows.go index ced978b0..fdafce96 100644 --- a/os_windows.go +++ b/os_windows.go @@ -69,6 +69,8 @@ func init() { gMarksPath = filepath.Join(data, "lf", "marks") gHistoryPath = filepath.Join(data, "lf", "history") + + exportEnvVars() } func detachedCommand(name string, arg ...string) *exec.Cmd {