diff --git a/eval.go b/eval.go index d049522..ed6947c 100644 --- a/eval.go +++ b/eval.go @@ -3,6 +3,7 @@ package main import ( "fmt" "log" + "os" "strconv" "strings" ) @@ -134,10 +135,16 @@ func (e *CallExpr) eval(app *App, args []string) { return } - curr := app.nav.currFile() path := app.nav.currPath() - if !curr.IsDir() && gSelectionPath == "" { + f, err := os.Stat(path) + if err != nil { + app.ui.message = err.Error() + log.Print(err) + return + } + + if !f.IsDir() && gSelectionPath == "" { if len(app.nav.marks) == 0 { app.runShell(fmt.Sprintf("%s '%s'", gOpts.opener, path), nil, false, false) } else { diff --git a/nav.go b/nav.go index d875063..1e91249 100644 --- a/nav.go +++ b/nav.go @@ -289,10 +289,14 @@ func (nav *Nav) updir() error { } func (nav *Nav) open() error { - curr := nav.currFile() path := nav.currPath() - if curr.IsDir() { + 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]) diff --git a/ui.go b/ui.go index 0c16ea3..546056d 100644 --- a/ui.go +++ b/ui.go @@ -295,19 +295,28 @@ func (ui *UI) draw(nav *Nav) { ui.wins[woff+i].printd(nav.dirs[doff+i], nav.marks) } + defer ui.msgwin.print(0, 0, fg, bg, ui.message) + if gOpts.preview { if len(dir.fi) == 0 { return } preview := ui.wins[len(ui.wins)-1] - curr := nav.currFile() path := nav.currPath() - if curr.IsDir() { + + f, err := os.Stat(path) + if err != nil { + ui.message = err.Error() + log.Print(err) + return + } + + if f.IsDir() { dir := newDir(path) dir.load(nav.inds[path], nav.poss[path], nav.height, nav.names[path]) preview.printd(dir, nav.marks) - } else { + } else if f.Mode().IsRegular() { file, err := os.Open(path) if err != nil { ui.message = err.Error() @@ -320,8 +329,6 @@ func (ui *UI) draw(nav *Nav) { } } } - - ui.msgwin.print(0, 0, fg, bg, ui.message) } func findBinds(keys map[string]Expr, prefix string) (binds map[string]Expr, ok bool) {