Work on getting browser sessions
This commit is contained in:
parent
a03f288682
commit
f0c98c5544
1 changed files with 28 additions and 8 deletions
36
main.go
36
main.go
|
@ -2,7 +2,10 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
tea "github.com/charmbracelet/bubbletea"
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
)
|
)
|
||||||
|
@ -36,14 +39,31 @@ var browserSelection SelectionSet
|
||||||
var commandSelection SelectionSet
|
var commandSelection SelectionSet
|
||||||
|
|
||||||
func getBrowserSessions() []sessionOrCommand {
|
func getBrowserSessions() []sessionOrCommand {
|
||||||
// Placeholder
|
// 1. List files in $XDG_DATA_HOME/qutebrowser/sessions/ (N.B.:
|
||||||
return []sessionOrCommand{{
|
// UserConfigDir() in os)
|
||||||
displayString: "primary",
|
userConfigDir, err := os.UserConfigDir()
|
||||||
commandString: "",
|
if err != nil {
|
||||||
}, {
|
log.Printf("Error finding user configuration directory: %v", err)
|
||||||
displayString: "breakfast",
|
return []sessionOrCommand{}
|
||||||
commandString: "",
|
}
|
||||||
}}
|
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 {
|
func initialModel() model {
|
||||||
|
|
Loading…
Reference in a new issue