Refactor exportFiles function

This commit is contained in:
Joe Lim committed 2023-06-18 16:36:47 +10:00
1 parent 03f1c3b44c
commit 475d11480b
3 files changed
+15 -40

No files matched your search

+15 -3
View File
@@ -655,12 +655,24 @@ func (nav *nav) exportFiles() {
var currFile string var currFile string
if curr, err := nav.currFile(); err == nil { 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) { func (nav *nav) dirPreviewLoop(ui *ui) {
-15
View File
@@ -218,21 +218,6 @@ func errCrossDevice(err error) bool {
return err.(*os.LinkError).Err.(unix.Errno) == unix.EXDEV 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 { func quoteString(s string) string {
return s return s
} }
-22
View File
@@ -174,28 +174,6 @@ func errCrossDevice(err error) bool {
return err.(*os.LinkError).Err.(windows.Errno) == 17 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 { func quoteString(s string) string {
return fmt.Sprintf(`"%s"`, s) return fmt.Sprintf(`"%s"`, s)
} }