diff --git a/eval.go b/eval.go index ed6947c..58c2add 100644 --- a/eval.go +++ b/eval.go @@ -144,17 +144,7 @@ func (e *CallExpr) eval(app *App, args []string) { return } - if !f.IsDir() && gSelectionPath == "" { - if len(app.nav.marks) == 0 { - app.runShell(fmt.Sprintf("%s '%s'", gOpts.opener, path), nil, false, false) - } else { - s := gOpts.opener - for m := range app.nav.marks { - s += fmt.Sprintf(" '%s'", m) - } - app.runShell(s, nil, false, false) - } - } else { + if f.IsDir() { err := app.nav.open() if err != nil { app.ui.message = err.Error() @@ -162,6 +152,44 @@ func (e *CallExpr) eval(app *App, args []string) { return } app.ui.echoFileInfo(app.nav) + return + } + + if gSelectionPath != "" { + out, err := os.Create(gSelectionPath) + if err != nil { + msg := fmt.Sprintf("open: %s", err) + app.ui.message = msg + log.Print(msg) + return + } + defer out.Close() + + if len(app.nav.marks) != 0 { + marks := app.nav.currMarks() + path = strings.Join(marks, "\n") + } + + _, err = out.WriteString(path) + if err != nil { + msg := fmt.Sprintf("open: %s", err) + app.ui.message = msg + log.Print(msg) + return + } + + gExitFlag = true + return + } + + if len(app.nav.marks) == 0 { + app.runShell(fmt.Sprintf("%s '%s'", gOpts.opener, path), nil, false, false) + } else { + s := gOpts.opener + for m := range app.nav.marks { + s += fmt.Sprintf(" '%s'", m) + } + app.runShell(s, nil, false, false) } case "bot": app.nav.bot() diff --git a/nav.go b/nav.go index 1e91249..84c59cc 100644 --- a/nav.go +++ b/nav.go @@ -291,42 +291,17 @@ func (nav *Nav) updir() error { func (nav *Nav) open() error { path := nav.currPath() - f, err := os.Stat(path) + dir := newDir(path) + + dir.load(nav.inds[path], nav.poss[path], nav.height, nav.names[path]) + + nav.dirs = append(nav.dirs, dir) + + err := os.Chdir(path) if err != nil { return fmt.Errorf("open: %s", err) } - if f.IsDir() { - dir := newDir(path) - - dir.load(nav.inds[path], nav.poss[path], nav.height, nav.names[path]) - - nav.dirs = append(nav.dirs, dir) - - err := os.Chdir(path) - if err != nil { - return fmt.Errorf("open: %s", err) - } - } else { - f, err := os.Create(gSelectionPath) - if err != nil { - return fmt.Errorf("open: %s", err) - } - defer f.Close() - - if len(nav.marks) != 0 { - marks := nav.currMarks() - path = strings.Join(marks, "\n") - } - - _, err = f.WriteString(path) - if err != nil { - return fmt.Errorf("open: %s", err) - } - - gExitFlag = true - } - return nil }