Skip to content

Commit 9b447fa

Browse files
author
weijie
committed
feat: enable select repo to editor
1 parent fbd8999 commit 9b447fa

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

tracegit

16.8 KB
Binary file not shown.

tui.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"fmt"
55
"os"
6+
"os/exec"
67
"strings"
78

89
"github.com/Cwjiee/tracegit/utils"
@@ -16,6 +17,7 @@ import (
1617

1718
var docStyle = lipgloss.NewStyle().Margin(1, 2)
1819
var items []list.Item
20+
var redirectRepo string
1921

2022
type item struct {
2123
title, desc string
@@ -98,6 +100,10 @@ func updateMain(msg tea.Msg, m model) (tea.Model, tea.Cmd) {
98100
case tea.KeyCtrlE:
99101
m.EditMode = true
100102
return m, nil
103+
case tea.KeyEnter:
104+
itemIndex := m.list.Index()
105+
redirectRepo = items[itemIndex].FilterValue()
106+
return m, tea.Quit
101107
}
102108
}
103109

@@ -162,10 +168,20 @@ func getFormatedData() []list.Item {
162168
func main() {
163169
getFormatedData()
164170
prefix := utils.GetPath(true)
171+
165172
p := tea.NewProgram(newModel(items, prefix), tea.WithAltScreen())
166173

167174
if _, err := p.Run(); err != nil {
168175
fmt.Println("Error running program:", err)
169176
os.Exit(1)
170177
}
178+
179+
if redirectRepo != "" {
180+
redirectRepoPath := prefix + "/" + redirectRepo
181+
cmd := exec.Command("zed", redirectRepoPath)
182+
if err := cmd.Run(); err != nil {
183+
cmd = exec.Command("vim", redirectRepoPath)
184+
cmd.Run()
185+
}
186+
}
171187
}

0 commit comments

Comments
 (0)