-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
160 lines (128 loc) · 3.29 KB
/
main.go
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package main
import (
"fmt"
"io"
"os"
"os/exec"
"os/user"
"path/filepath"
)
var (
home string
dotfilesPath string
)
func main() {
home = getCurrentUser().HomeDir
dotfilesPath = filepath.Join(home, "Documents/Code/dotfiles")
if len(os.Args) > 1 {
if os.Args[1] == "pull" {
if dotfilesDirectoryExists() {
pullLatestDotfiles()
}
return
}
if os.Args[1] == "sync" {
if dotfilesDirectoryExists() {
pullLatestDotfiles()
moveConfigFiles()
}
return
}
}
StartUI()
}
func dotfilesDirectoryExists() bool {
_, err := os.Stat(dotfilesPath)
if os.IsNotExist(err) {
fmt.Println("Dotfiles directory does not exist")
return false
}
return true
}
func pullLatestDotfiles() {
fmt.Println("Pulling latest dotfiles...")
cmd := exec.Command("git", "pull")
cmd.Dir = dotfilesPath
err := cmd.Run()
if err != nil {
fmt.Println("Failed to pull latest dotfiles:", err)
return
}
fmt.Println("Dotfiles pulled successfully")
}
func moveConfigFiles() {
fmt.Println("Moving config files...")
copyWeztermConfig()
copyVSCodeConfig()
copyDarkReaderSettings()
copyStreamLinkConfig()
}
func copyWeztermConfig() {
weztermConfigPath := filepath.Join(home, ".wezterm.lua")
dotfilesWeztermConfigPath := filepath.Join(dotfilesPath, ".wezterm/.wezterm.lua")
if configFileExists(weztermConfigPath) {
fmt.Println("Copying Wezterm config file")
copyFile(weztermConfigPath, dotfilesWeztermConfigPath)
} else {
fmt.Println("Wezterm config file does not exist")
}
}
func copyVSCodeConfig() {
VSCodeSettingsPath := filepath.Join(home, "AppData/Roaming/Code/User/settings.json")
VSCodeKeybindingsPath := filepath.Join(home, "AppData/Roaming/Code/User/keybindings.json")
VSCodeSettingsInDotfiles := filepath.Join(dotfilesPath, ".config/Code/User/settings.json")
VSCodeKeybindingsInDotfiles := filepath.Join(dotfilesPath, ".config/Code/User/keybindings.json")
if configFileExists(VSCodeSettingsPath) {
fmt.Println("Copying VSCode settings file")
copyFile(VSCodeSettingsPath, VSCodeSettingsInDotfiles)
} else {
fmt.Println("VSCode settings file does not exist")
}
if configFileExists(VSCodeKeybindingsPath) {
fmt.Println("Copying VSCode keybindings file")
copyFile(VSCodeKeybindingsPath, VSCodeKeybindingsInDotfiles)
} else {
fmt.Println("VSCode keybindings file does not exist")
}
}
func copyStreamLinkConfig() {
streamlinkConfigPath := filepath.Join(home, "AppData/Roaming/streamlink/config")
if configFileExists(streamlinkConfigPath) {
fmt.Println("Copying Streamlink config file")
copyFile(streamlinkConfigPath, dotfilesPath)
} else {
fmt.Println("Streamlink config file does not exist")
}
}
func copyDarkReaderSettings() {
// TODO
}
func copyFile(sourcePath string, destinationPath string) error {
sourceFile, err := os.Open(sourcePath)
if err != nil {
return err
}
defer sourceFile.Close()
destinationFile, err := os.Create(destinationPath)
if err != nil {
return err
}
defer destinationFile.Close()
_, err = io.Copy(destinationFile, sourceFile)
if err != nil {
return err
}
return nil
}
func configFileExists(path string) bool {
_, err := os.Stat(path)
return !os.IsNotExist(err)
}
func getCurrentUser() *user.User {
currentUser, err := user.Current()
if err != nil {
fmt.Println("Error:", err)
return nil
}
return currentUser
}