-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
71 lines (62 loc) · 1.35 KB
/
main.go
File metadata and controls
71 lines (62 loc) · 1.35 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
package main
import (
"bufio"
"fmt"
"log"
"os"
"runtime"
"strings"
"github.com/adrg/xdg"
"github.com/lmorg/ttyphoon/app"
"github.com/lmorg/ttyphoon/debug"
"github.com/lmorg/ttyphoon/utils/cache"
"github.com/lmorg/ttyphoon/utils/file"
)
func main() {
if runtime.GOOS == "darwin" {
err := os.Setenv("PATH", "PATH="+os.Getenv("PATH")+":/usr/bin:/opt/homebrew/bin:/opt/homebrew/sbin")
if err != nil {
panic(err)
}
}
loadEnvs()
cacheDbFile := "cache.db"
cacheDbPath, err := xdg.CacheFile(cacheDbFile)
if err != nil {
log.Println(err)
cacheDbPath = fmt.Sprintf("%s/%s-%s", os.TempDir(), app.DirName, cacheDbFile)
}
cache.SetPath(cacheDbPath)
cache.InitCache()
startWails()
}
func loadEnvs() {
files := file.GetConfigFiles("/", ".env")
for i := range files {
f, err := os.Open(files[i])
if err != nil {
log.Print(err)
continue
}
scanner := bufio.NewScanner(f)
for scanner.Scan() {
split := strings.SplitN(scanner.Text(), "=", 2)
if len(split) != 2 {
split = []string{files[i], ""}
}
debug.Log(fmt.Sprintf(`%s: "%s" = "%s"`, files[i], split[0], split[1]))
os.Setenv(split[0], split[1])
}
}
}
func cdHome() {
// default to $HOME
home, err := os.UserHomeDir()
if err != nil {
os.Stderr.WriteString(err.Error())
} else {
if err = os.Chdir(home); err != nil {
os.Stderr.WriteString(err.Error())
}
}
}