From 6f35abb4ca83ce2f3591436871c1ee1c842753ee Mon Sep 17 00:00:00 2001 From: Gokcehan Date: Sun, 17 Mar 2019 20:16:19 +0300 Subject: [PATCH] quote file variables on windows --- app.go | 17 ++++------------- os.go | 15 +++++++++++++++ os_windows.go | 22 +++++++++++++++++++++- 3 files changed, 40 insertions(+), 14 deletions(-) diff --git a/app.go b/app.go index ac680aef..b59e9e7f 100644 --- a/app.go +++ b/app.go @@ -283,23 +283,14 @@ func (app *app) loop() { } func (app *app) exportFiles() { - var envFile string + var currFile string if f, err := app.nav.currFile(); err == nil { - envFile = f.path + currFile = f.path } - selections := app.nav.currSelections() + currSelections := app.nav.currSelections() - envFiles := strings.Join(selections, gOpts.filesep) - - os.Setenv("f", envFile) - os.Setenv("fs", envFiles) - - if len(selections) == 0 { - os.Setenv("fx", envFile) - } else { - os.Setenv("fx", envFiles) - } + exportFiles(currFile, currSelections) } func waitKey() error { diff --git a/os.go b/os.go index 43a7d8fd..843776a9 100644 --- a/os.go +++ b/os.go @@ -10,6 +10,7 @@ import ( "os/user" "path/filepath" "runtime" + "strings" ) var ( @@ -133,3 +134,17 @@ func moveCursor(y, x int) { func isExecutable(f os.FileInfo) bool { return f.Mode()&0111 != 0 } + +func exportFiles(f string, fs []string) { + envFile := f + envFiles := strings.Join(fs, gOpts.filesep) + + os.Setenv("f", envFile) + os.Setenv("fs", envFiles) + + if len(fs) == 0 { + os.Setenv("fx", envFile) + } else { + os.Setenv("fx", envFiles) + } +} diff --git a/os_windows.go b/os_windows.go index fdafce96..9c4eeb65 100644 --- a/os_windows.go +++ b/os_windows.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "log" "os" "os/exec" @@ -36,7 +37,7 @@ var ( func init() { if envOpener == "" { - envOpener = "start" + envOpener = `start ""` } if envEditor == "" { @@ -116,3 +117,22 @@ func isExecutable(f os.FileInfo) bool { } return false } + +func exportFiles(f string, fs []string) { + envFile := fmt.Sprintf(`"%s"`, f) + + var quotedFiles []string + for _, f := range fs { + quotedFiles = append(quotedFiles, fmt.Sprintf(`"%s"`, f)) + } + envFiles := strings.Join(quotedFiles, gOpts.filesep) + + os.Setenv("f", envFile) + os.Setenv("fs", envFiles) + + if len(fs) == 0 { + os.Setenv("fx", envFile) + } else { + os.Setenv("fx", envFiles) + } +}