Work on getting browser sessions

This commit is contained in:
Adam Cooper 2022-05-13 08:50:25 -04:00
parent a03f288682
commit f0c98c5544

36
main.go
View file

@ -2,7 +2,10 @@ package main
import (
"fmt"
"io/fs"
"log"
"os"
"strings"
tea "github.com/charmbracelet/bubbletea"
)
@ -36,14 +39,31 @@ var browserSelection SelectionSet
var commandSelection SelectionSet
func getBrowserSessions() []sessionOrCommand {
// Placeholder
return []sessionOrCommand{{
displayString: "primary",
commandString: "",
}, {
displayString: "breakfast",
commandString: "",
}}
// 1. List files in $XDG_DATA_HOME/qutebrowser/sessions/ (N.B.:
// UserConfigDir() in os)
userConfigDir, err := os.UserConfigDir()
if err != nil {
log.Printf("Error finding user configuration directory: %v", err)
return []sessionOrCommand{}
}
log.Printf("INFO userConfigDir: %+v", userConfigDir)
fileSystem := os.DirFS(userConfigDir)
log.Printf("INFO fileSystem: %+v", fileSystem)
fileList, err := fs.ReadDir(fileSystem, "/qutebrowser/sessions")
if err != nil {
log.Printf("Error reading browser sessions directory: %v", err)
return []sessionOrCommand{}
}
// 2. Exclude non-YAML files
// 3. Wrangle them into this struct array
result := make([]sessionOrCommand, len(fileList))
for _, entry := range fileList {
if !entry.IsDir() && strings.HasSuffix(entry.Name(), ".yml") {
result = append(result, sessionOrCommand{displayString: entry.Name(), commandString: ""})
}
}
// log.Printf("result: %v", result)
return result
}
func initialModel() model {