export permanent env vars on startup

Related #134
This commit is contained in:
Gokcehan committed 2019-03-17 19:52:34 +03:00
1 parent 1eedd29546
commit 0eedb71d6c
4 files changed
+25 -19

No files matched your search

+2 -19
View File
@@ -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)
+19
View File
@@ -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 {
+2
View File
@@ -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 {
+2
View File
@@ -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 {