mirror of
https://github.com/eeeXun/GTT.git
synced 2025-05-17 16:20:33 -07:00
32 lines
801 B
Go
32 lines
801 B
Go
package main
|
|
|
|
import (
|
|
config "github.com/spf13/viper"
|
|
"os"
|
|
)
|
|
|
|
func configInit() {
|
|
var defaultConfigPath string
|
|
|
|
config.SetConfigName("gtt")
|
|
config.SetConfigType("yaml")
|
|
if len(os.Getenv("$XDG_CONFIG_HOME")) > 0 {
|
|
defaultConfigPath = os.Getenv("$XDG_CONFIG_HOME") + "/gtt"
|
|
config.AddConfigPath(defaultConfigPath)
|
|
} else {
|
|
defaultConfigPath = os.Getenv("HOME") + "/.config/gtt"
|
|
}
|
|
config.AddConfigPath("$HOME/.config/gtt")
|
|
|
|
if err := config.ReadInConfig(); err != nil {
|
|
config.Set("transparent", false)
|
|
config.Set("theme", "Gruvbox")
|
|
config.Set("source_language", "English")
|
|
config.Set("destination_language", "Chinese (Traditional)")
|
|
if _, err = os.Stat(defaultConfigPath); os.IsNotExist(err) {
|
|
os.Mkdir(defaultConfigPath, os.ModePerm)
|
|
}
|
|
config.SafeWriteConfig();
|
|
}
|
|
}
|