FIXED #5 Fixed qutebrowser launch command

Truncate ".yml" from session file name for launch command
This commit is contained in:
Adam Cooper 2022-05-16 09:21:51 -04:00
parent a529d22cab
commit cc1a424f2b

33
main.go
View file

@ -61,7 +61,10 @@ func getBrowserSessions() []sessionOrCommand {
for _, entry := range fileList {
if !entry.IsDir() && strings.HasSuffix(entry.Name(), ".yml") {
log.Printf("INFO %s", entry.Name())
result = append(result, sessionOrCommand{displayString: strings.TrimSuffix(entry.Name(), ".yml"), command: nil})
result = append(result, sessionOrCommand{
displayString: strings.TrimSuffix(entry.Name(), ".yml"),
command: exec.Command("qutebrowser", "--restore", strings.TrimSuffix(entry.Name(), ".yml")),
})
}
}
// log.Printf("result: %v", result)
@ -82,6 +85,9 @@ func initialModel() model {
}, {
displayString: "bottom",
command: exec.Command("xterm", "-maximized", "-e", "btm", "--group", "--battery", "--color", "gruvbox-light"),
}, {
displayString: "broot",
command: exec.Command("xterm", "-maximized", "-e", "broot"),
}},
},
// An array of maps which indicates which choices are selected.
@ -94,29 +100,20 @@ func initialModel() model {
func launch(m model) tea.Cmd {
return func() tea.Msg {
var result statusMsg
for j, item := range m.choices[BrowserSessions] {
if _, ok := m.selected[BrowserSessions][j]; ok {
cmd := exec.Command("qutebrowser", "--restore", item.displayString)
err := cmd.Start()
result += statusMsg(fmt.Sprintf("Launching Qutebrowser session: %v\n", item.displayString))
for p := 0; p < 2; p++ {
for q, item := range m.choices[p] {
if _, ok := m.selected[p][q]; ok {
log.Printf("INFO launching: %v\n", item.displayString)
result += statusMsg(fmt.Sprintf("Launching command: %v\n", item.displayString))
err := item.command.Start()
if err != nil {
result += statusMsg(fmt.Sprintf("%v\n", err))
log.Fatalf("Error starting browser session: %v\n", err)
log.Fatalf("Error launching: %v\n", err)
}
}
}
}
for k, item := range m.choices[Commands] {
if _, ok := m.selected[Commands][k]; ok {
cmd := item.command
err := cmd.Start()
result += statusMsg(fmt.Sprintf("Launching command: %v\n", item.displayString))
if err != nil {
result += statusMsg(fmt.Sprintf("%v\n", err))
log.Fatalf("Error starting command: %v\n", err)
}
}
}
return result
}
}