From 475d11480b3b635c35cf4b2c8f72394223083342 Mon Sep 17 00:00:00 2001 From: Joe Lim <50560759+joelim-work@users.noreply.github.com> Date: Sun, 18 Jun 2023 16:36:47 +1000 Subject: [PATCH] Refactor `exportFiles` function --- nav.go | 18 +++++++++++++++--- os.go | 15 --------------- os_windows.go | 22 ---------------------- 3 files changed, 15 insertions(+), 40 deletions(-) diff --git a/nav.go b/nav.go index d4912378..9322596c 100644 --- a/nav.go +++ b/nav.go @@ -655,12 +655,24 @@ func (nav *nav) exportFiles() { var currFile string if curr, err := nav.currFile(); err == nil { - currFile = curr.path + currFile = quoteString(curr.path) } - currSelections := nav.currSelections() + var selections []string + for _, selection := range nav.currSelections() { + selections = append(selections, quoteString(selection)) + } + currSelections := strings.Join(selections, gOpts.filesep) - exportFiles(currFile, currSelections, nav.currDir().path) + os.Setenv("f", currFile) + os.Setenv("fs", currSelections) + os.Setenv("PWD", quoteString(nav.currDir().path)) + + if len(selections) == 0 { + os.Setenv("fx", currFile) + } else { + os.Setenv("fx", currSelections) + } } func (nav *nav) dirPreviewLoop(ui *ui) { diff --git a/os.go b/os.go index 05c71d2d..f26f5433 100644 --- a/os.go +++ b/os.go @@ -218,21 +218,6 @@ func errCrossDevice(err error) bool { return err.(*os.LinkError).Err.(unix.Errno) == unix.EXDEV } -func exportFiles(f string, fs []string, pwd string) { - envFile := f - envFiles := strings.Join(fs, gOpts.filesep) - - os.Setenv("f", envFile) - os.Setenv("fs", envFiles) - os.Setenv("PWD", pwd) - - if len(fs) == 0 { - os.Setenv("fx", envFile) - } else { - os.Setenv("fx", envFiles) - } -} - func quoteString(s string) string { return s } diff --git a/os_windows.go b/os_windows.go index 5d006980..7d3f3452 100644 --- a/os_windows.go +++ b/os_windows.go @@ -174,28 +174,6 @@ func errCrossDevice(err error) bool { return err.(*os.LinkError).Err.(windows.Errno) == 17 } -func exportFiles(f string, fs []string, pwd 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) - - envPWD := fmt.Sprintf(`"%s"`, pwd) - - os.Setenv("f", envFile) - os.Setenv("fs", envFiles) - os.Setenv("PWD", envPWD) - - if len(fs) == 0 { - os.Setenv("fx", envFile) - } else { - os.Setenv("fx", envFiles) - } -} - func quoteString(s string) string { return fmt.Sprintf(`"%s"`, s) }