handle dir symlinks in preview and open

This commit is contained in:
Gokcehan 2016-08-14 15:15:54 +03:00
parent 84cf8e12c3
commit 6a2bdf472b
3 changed files with 27 additions and 9 deletions

11
eval.go
View File

@ -3,6 +3,7 @@ package main
import ( import (
"fmt" "fmt"
"log" "log"
"os"
"strconv" "strconv"
"strings" "strings"
) )
@ -134,10 +135,16 @@ func (e *CallExpr) eval(app *App, args []string) {
return return
} }
curr := app.nav.currFile()
path := app.nav.currPath() 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 { if len(app.nav.marks) == 0 {
app.runShell(fmt.Sprintf("%s '%s'", gOpts.opener, path), nil, false, false) app.runShell(fmt.Sprintf("%s '%s'", gOpts.opener, path), nil, false, false)
} else { } else {

8
nav.go
View File

@ -289,10 +289,14 @@ func (nav *Nav) updir() error {
} }
func (nav *Nav) open() error { func (nav *Nav) open() error {
curr := nav.currFile()
path := nav.currPath() 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 := newDir(path)
dir.load(nav.inds[path], nav.poss[path], nav.height, nav.names[path]) dir.load(nav.inds[path], nav.poss[path], nav.height, nav.names[path])

17
ui.go
View File

@ -295,19 +295,28 @@ func (ui *UI) draw(nav *Nav) {
ui.wins[woff+i].printd(nav.dirs[doff+i], nav.marks) 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 gOpts.preview {
if len(dir.fi) == 0 { if len(dir.fi) == 0 {
return return
} }
preview := ui.wins[len(ui.wins)-1] preview := ui.wins[len(ui.wins)-1]
curr := nav.currFile()
path := nav.currPath() 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 := newDir(path)
dir.load(nav.inds[path], nav.poss[path], nav.height, nav.names[path]) dir.load(nav.inds[path], nav.poss[path], nav.height, nav.names[path])
preview.printd(dir, nav.marks) preview.printd(dir, nav.marks)
} else { } else if f.Mode().IsRegular() {
file, err := os.Open(path) file, err := os.Open(path)
if err != nil { if err != nil {
ui.message = err.Error() 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) { func findBinds(keys map[string]Expr, prefix string) (binds map[string]Expr, ok bool) {