move selection path handling to eval

This commit is contained in:
Gokcehan 2016-08-14 15:37:22 +03:00
parent 6a2bdf472b
commit fac1c9e8de
2 changed files with 46 additions and 43 deletions

48
eval.go
View File

@ -144,7 +144,44 @@ func (e *CallExpr) eval(app *App, args []string) {
return
}
if !f.IsDir() && gSelectionPath == "" {
if f.IsDir() {
err := app.nav.open()
if err != nil {
app.ui.message = err.Error()
log.Print(err)
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 {
@ -154,15 +191,6 @@ func (e *CallExpr) eval(app *App, args []string) {
}
app.runShell(s, nil, false, false)
}
} else {
err := app.nav.open()
if err != nil {
app.ui.message = err.Error()
log.Print(err)
return
}
app.ui.echoFileInfo(app.nav)
}
case "bot":
app.nav.bot()
app.ui.echoFileInfo(app.nav)

25
nav.go
View File

@ -291,12 +291,6 @@ func (nav *Nav) updir() error {
func (nav *Nav) open() error {
path := nav.currPath()
f, err := os.Stat(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])
@ -307,25 +301,6 @@ func (nav *Nav) open() error {
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
}