Skip to content

Commit

Permalink
move selection path handling to eval
Browse files Browse the repository at this point in the history
  • Loading branch information
gokcehan committed Aug 14, 2016
1 parent 6a2bdf4 commit fac1c9e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 42 deletions.
50 changes: 39 additions & 11 deletions eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,24 +144,52 @@ 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()
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 {
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()
Expand Down
37 changes: 6 additions & 31 deletions nav.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,40 +291,15 @@ 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)
}
dir := newDir(path)

if f.IsDir() {
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])
nav.dirs = append(nav.dirs, dir)

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
err := os.Chdir(path)
if err != nil {
return fmt.Errorf("open: %s", err)
}

return nil
Expand Down

0 comments on commit fac1c9e

Please sign in to comment.