Skip to content

Commit

Permalink
handle dir symlinks in preview and open
Browse files Browse the repository at this point in the history
  • Loading branch information
gokcehan committed Aug 14, 2016
1 parent 84cf8e1 commit 6a2bdf4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
11 changes: 9 additions & 2 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"fmt"
"log"
"os"
"strconv"
"strings"
)
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions nav.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
17 changes: 12 additions & 5 deletions ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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) {
Expand Down

0 comments on commit 6a2bdf4

Please sign in to comment.