Skip to content

Commit

Permalink
Open editor upon repo selection
Browse files Browse the repository at this point in the history
- select via enter
- VS Code for now
  • Loading branch information
carhartl committed Oct 23, 2024
1 parent 1e013f4 commit 9837db2
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions cmd/git-unsaved/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/fs"
"log"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
Expand Down Expand Up @@ -61,6 +62,11 @@ func (m model) Init() tea.Cmd {

func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.KeyMsg:
switch msg.String() {
case "enter":
return m, openEditor(m.list.SelectedItem().(repo).path)
}
case tea.WindowSizeMsg:
h, v := docStyle.GetFrameSize()
m.list.SetSize(msg.Width-h, msg.Height-v)
Expand Down Expand Up @@ -149,6 +155,13 @@ func waitForRepoStatus(sub chan repoMsg) tea.Cmd {
}
}

func openEditor(path string) tea.Cmd {
c := exec.Command("code", path)
return tea.ExecProcess(c, func(err error) tea.Msg {
return nil
})
}

func addDefaultGitignoreToWorktree(w *git.Worktree) {
home, err := os.UserHomeDir()
if err != nil {
Expand Down

0 comments on commit 9837db2

Please sign in to comment.