File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -97,6 +97,7 @@ If you want the exact delta configuration I'm using - [it can be found here](htt
9797| <kbd>e</kbd> | Toggle the file tree |
9898| <kbd>t</kbd> | Search/go-to file |
9999| <kbd>y</kbd> | Copy file path |
100+ | <kbd>o</kbd> | Open file in $EDITOR |
100101| <kbd>Tab</kbd> | Switch focus between the panes |
101102| <kbd>q</kbd> | Quit |
102103
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ type KeyMap struct {
1212 Quit key.Binding
1313 Copy key.Binding
1414 TogglePanel key.Binding
15+ OpenInEditor key.Binding
1516}
1617
1718var keys = & KeyMap {
@@ -51,6 +52,10 @@ var keys = &KeyMap{
5152 key .WithKeys ("tab" ),
5253 key .WithHelp ("TAB" , "switch panel" ),
5354 ),
55+ OpenInEditor : key .NewBinding (
56+ key .WithKeys ("o" ),
57+ key .WithHelp ("o" , "open" ),
58+ ),
5459}
5560
5661func getKeys () []key.Binding {
@@ -63,6 +68,7 @@ func getKeys() []key.Binding {
6368 keys .ToggleFileTree ,
6469 keys .Search ,
6570 keys .Copy ,
71+ keys .OpenInEditor ,
6672 keys .Quit ,
6773 }
6874}
Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ package ui
22
33import (
44 "fmt"
5+ "os"
6+ "os/exec"
57 "strings"
68
79 "github.com/bluekeyes/go-gitdiff/gitdiff"
@@ -176,6 +178,11 @@ func (m mainModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
176178 if cmd != nil {
177179 cmds = append (cmds , cmd )
178180 }
181+ case "o" :
182+ cmd = m .openInEditor ()
183+ if cmd != nil {
184+ cmds = append (cmds , cmd )
185+ }
179186 }
180187
181188 case tea.WindowSizeMsg :
@@ -456,6 +463,23 @@ func (m *mainModel) setCursor(cursor int) tea.Cmd {
456463 return cmd
457464}
458465
466+ func (m mainModel ) openInEditor () tea.Cmd {
467+ if len (m .files ) == 0 {
468+ return nil
469+ }
470+
471+ editor := os .Getenv ("EDITOR" )
472+ if editor == "" {
473+ return nil
474+ }
475+
476+ filePath := filenode .GetFileName (m .files [m .cursor ])
477+ c := exec .Command (editor , filePath )
478+ return tea .ExecProcess (c , func (err error ) tea.Msg {
479+ return nil
480+ })
481+ }
482+
459483func (m mainModel ) handleMouse (msg tea.MouseMsg ) (tea.Model , tea.Cmd ) {
460484 // Handle scroll wheel first.
461485 if msg .Button == tea .MouseButtonWheelUp || msg .Button == tea .MouseButtonWheelDown {
You can’t perform that action at this time.
0 commit comments