diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 50 |
1 files changed, 50 insertions, 0 deletions
@@ -0,0 +1,50 @@ +package main + +import ( + "fmt" + "os" + "os/exec" + "syscall" + + tea "github.com/charmbracelet/bubbletea" +) + +type item struct { + title string + contents string +} + +func (i item) Title() string { return i.title } +func (i item) Description() string { return i.contents } +func (i item) FilterValue() string { return i.title } + +func main() { + if e := runProgram(); e != nil { + fmt.Println(e) + os.Exit(1) + } +} + +func runProgram() error { + + model, err := tea.NewProgram(StartSelecting(), tea.WithMouseCellMotion()).Run() + if err != nil { + return fmt.Errorf("Error running program: %s", err) + } + if confirm, ok := model.(confirmModel); ok && confirm.doRun { + sh, err := exec.LookPath("sh") + if err != nil { + return fmt.Errorf("could not find sh: %s", err) + } + + args := []string{"-v", "-c"} + args = append(args, "set -v; "+confirm.selected.contents) + + err = syscall.Exec(sh, args, os.Environ()) + if err != nil { + return fmt.Errorf("could not exec: %s", err) + } + } + + return nil +} |