Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/knipferrc/fm
Browse files Browse the repository at this point in the history
  • Loading branch information
mistakenelf committed Oct 7, 2021
2 parents 35ca858 + 65ae029 commit 66b9431
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ go install github.com/knipferrc/fm@latest
- Themes (default, gruvbox, spooky)
- Render PNG, JPG and JPEG as strings
- Colors adapt to terminal background
- Open selected file in editor set in EDITOR environment variable (currently only supports GUI editors)

## Themes

Expand Down Expand Up @@ -103,6 +104,7 @@ go install github.com/knipferrc/fm@latest
| n | Create a new file in the current directory |
| N | Create a new directory in the current directory |
| r | Rename the currently selected file or directory |
| E | Open in editor set in EDITOR environment variable |

## Configuration

Expand Down
7 changes: 7 additions & 0 deletions internal/ui/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type keyMap struct {
CreateFile key.Binding
CreateDirectory key.Binding
Rename key.Binding
EditFile key.Binding
}

// ShortHelp returns keybindings to be shown in the mini help view. It's part
Expand Down Expand Up @@ -54,6 +55,7 @@ func (k keyMap) ShortHelp() []key.Binding {
k.CreateFile,
k.CreateDirectory,
k.Rename,
k.EditFile,
}
}

Expand Down Expand Up @@ -84,6 +86,7 @@ func (k keyMap) FullHelp() [][]key.Binding {
k.CreateFile,
k.CreateDirectory,
k.Rename,
k.EditFile,
},
}
}
Expand Down Expand Up @@ -179,5 +182,9 @@ func getDefaultKeyMap() keyMap {
key.WithKeys("r"),
key.WithHelp("r", "rename the currently selected file or directory"),
),
EditFile: key.NewBinding(
key.WithKeys("E"),
key.WithHelp("E", "edit the currently selected file"),
),
}
}
27 changes: 27 additions & 0 deletions internal/ui/update.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package ui

import (
"errors"
"fmt"
"os"
"os/exec"

"github.com/knipferrc/fm/dirfs"

Expand Down Expand Up @@ -517,6 +519,31 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
)
}

// Edit the currently selected file.
case key.Matches(msg, m.keys.EditFile):
if !m.showCommandBar && m.primaryPane.GetIsActive() && !m.dirTree.GetSelectedFile().IsDir() {
editorPath := os.Getenv("EDITOR")
if editorPath == "" {
return m, m.handleErrorCmd(errors.New("$EDITOR not set"))
}

editorCmd := exec.Command(editorPath, m.dirTree.GetSelectedFile().Name())
editorCmd.Stdin = os.Stdin
editorCmd.Stdout = os.Stdout
editorCmd.Stderr = os.Stderr
err := editorCmd.Start()
if err != nil {
return m, m.handleErrorCmd(err)
}

err = editorCmd.Wait()
if err != nil {
return m, m.handleErrorCmd(err)
}
}

return m, m.updateDirectoryListingCmd(dirfs.CurrentDirectory)

// Reset FM to its initial state.
case key.Matches(msg, m.keys.Escape):
m.showCommandBar = false
Expand Down

0 comments on commit 66b9431

Please sign in to comment.