-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
74 lines (63 loc) · 1.74 KB
/
main.go
File metadata and controls
74 lines (63 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"context"
"fmt"
"os"
"path/filepath"
"github.com/knadh/koanf/parsers/toml"
"github.com/knadh/koanf/providers/confmap"
"github.com/knadh/koanf/providers/file"
"github.com/knadh/koanf/v2"
"github.com/urfave/cli/v3"
"github.com/winter-again/flow/internal/tmux"
)
var k = koanf.New(".")
func main() {
// TODO: create global --debug flag for logging?
if err := loadConfig(); err != nil {
fmt.Println(err)
os.Exit(1)
}
// NOTE: is this any better than rereading the config file in that package?
tmux.InitSessionName = k.String("flow.init_session_name")
cmd := &cli.Command{
Name: "flow",
Version: "v0.1.3",
Usage: "CLI for managing tmux sessions",
Commands: []*cli.Command{
Start(),
Attach(),
Switch(),
Find(),
},
}
if err := cmd.Run(context.Background(), os.Args); err != nil {
fmt.Println(err)
os.Exit(1) // NOTE: this might be redundant?
}
}
func loadConfig() error {
// TODO: should allow user to config this from fzf-tmux instead?
k.Load(confmap.Provider(map[string]any{
"flow.init_session_name": "0",
"fzf-tmux.length": "60%",
"fzf-tmux.width": "80%",
"fzf-tmux.border": "rounded",
"fzf-tmux.preview_size": "60%",
"fzf-tmux.preview_border": "rounded",
"fzf-tmux.preview_dir_cmd": []string{"ls"},
"fzf-tmux.preview_pos": "right",
// TODO: check if $HOME can be used
"find.dirs": []string{"$HOME"},
}, "."), nil)
home, err := os.UserHomeDir()
if err != nil {
return err
}
// TODO: what about --config flag for custom loc?
config := filepath.Join(home, ".config/flow/config.toml")
if err := k.Load(file.Provider(config), toml.Parser()); err != nil {
return fmt.Errorf("error loading config file: %w", err)
}
return nil
}