From a6c9dba25ad9204ebde302728eb2a75532497f37 Mon Sep 17 00:00:00 2001 From: Aria Date: Fri, 3 Feb 2023 12:14:41 +0000 Subject: initial commit --- main.go | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 main.go (limited to 'main.go') diff --git a/main.go b/main.go new file mode 100644 index 0000000..9656146 --- /dev/null +++ b/main.go @@ -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 +} -- cgit v1.2.3