Improve windows shell handling (#1309)
* Improve windows shell handling
* Add shell in command line
* Fix shellopts bug
* Add quote string
* Refactor `exportFiles` function
* Add defaults for Windows
* Revert "Add defaults for Windows"
Accidental commit
This reverts commit 5ff32650fe.
* Separate handling for CMD vs PowerShell
* Add case insensitive check
This commit is contained in:
1 parent
56ab5ccc61
commit
592e7fe4be
4 files changed
+35
-39
No files matched your search
@@ -85,7 +85,7 @@ func exportEnvVars() {
|
||||
log.Printf("getting path to lf binary: %s", err)
|
||||
lfPath = "lf"
|
||||
}
|
||||
os.Setenv("lf", lfPath)
|
||||
os.Setenv("lf", quoteString(lfPath))
|
||||
}
|
||||
|
||||
// used by exportOpts below
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -224,17 +224,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
|
||||
}
|
||||
+17
-22
@@ -101,10 +101,23 @@ func detachedCommand(name string, arg ...string) *exec.Cmd {
|
||||
}
|
||||
|
||||
func shellCommand(s string, args []string) *exec.Cmd {
|
||||
// Windows CMD requires special handling to deal with quoted arguments
|
||||
if strings.ToLower(gOpts.shell) == "cmd" {
|
||||
var builder strings.Builder
|
||||
builder.WriteString(s)
|
||||
for _, arg := range args {
|
||||
fmt.Fprintf(&builder, ` "%s"`, arg)
|
||||
}
|
||||
shellOpts := strings.Join(gOpts.shellopts, " ")
|
||||
cmdline := fmt.Sprintf(`%s %s %s "%s"`, gOpts.shell, shellOpts, gOpts.shellflag, builder.String())
|
||||
|
||||
cmd := exec.Command(gOpts.shell)
|
||||
cmd.SysProcAttr = &windows.SysProcAttr{CmdLine: cmdline}
|
||||
return cmd
|
||||
}
|
||||
|
||||
args = append([]string{gOpts.shellflag, s}, args...)
|
||||
|
||||
args = append(gOpts.shellopts, args...)
|
||||
|
||||
return exec.Command(gOpts.shell, args...)
|
||||
}
|
||||
|
||||
@@ -168,24 +181,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)
|
||||
}
|
||||
Reference in new issue
Block a user