From 9d406f8dfc21480bc47ce4ec664c1fb9f46d99cb Mon Sep 17 00:00:00 2001 From: Alexandre Date: Mon, 3 Feb 2025 09:54:58 +0100 Subject: [PATCH] Finally fixed the bug where the config won't be created --- main.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 51be4e9..86b0adb 100644 --- a/main.go +++ b/main.go @@ -70,9 +70,12 @@ func main() { // Charger la configuration depuis un fichier func loadConfig() { homeDir, _ := os.UserHomeDir() - configPath := homeDir + "/.config/gosh/gosh_config.toml" + configPath := homeDir + "/.config/gosh/" fmt.Println("Chemin du fichier de configuration:", configPath) - viper.SetConfigFile(configPath) + viper.AddConfigPath(configPath) + viper.SetConfigName("gosh_config") + viper.SetConfigType("toml") + // viper.SetConfigFile(configPath) // Valeurs par défaut viper.SetDefault("prompt", "[{dir}] > ") @@ -84,7 +87,7 @@ func loadConfig() { if _, ok := err.(viper.ConfigFileNotFoundError); ok { // Si le fichier n'existe pas, le créer avec les valeurs par défaut fmt.Println("Création du fichier de configuration avec les valeurs par défaut...") - if err := viper.WriteConfigAs(configPath); err != nil { + if err := viper.WriteConfigAs(configPath + "gosh_config"); err != nil { fmt.Fprintln(os.Stderr, "Erreur lors de la création du fichier de configuration:", err) } else { fmt.Println("Fichier de configuration créé avec succès:", configPath) @@ -132,6 +135,11 @@ func getPrompt() string { prompt = blue + prompt + reset } + if config.Color == "green" { + green := "\033[32m" + reset := "\033[0m" + prompt = green + prompt + reset + } return prompt }