mirror of
https://github.com/Alexandre1a/GoSH.git
synced 2026-03-10 03:29:47 +01:00
Finally fixed the bug where the config won't be created
This commit is contained in:
parent
a03c941412
commit
9d406f8dfc
14
main.go
14
main.go
@ -70,9 +70,12 @@ func main() {
|
|||||||
// Charger la configuration depuis un fichier
|
// Charger la configuration depuis un fichier
|
||||||
func loadConfig() {
|
func loadConfig() {
|
||||||
homeDir, _ := os.UserHomeDir()
|
homeDir, _ := os.UserHomeDir()
|
||||||
configPath := homeDir + "/.config/gosh/gosh_config.toml"
|
configPath := homeDir + "/.config/gosh/"
|
||||||
fmt.Println("Chemin du fichier de configuration:", configPath)
|
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
|
// Valeurs par défaut
|
||||||
viper.SetDefault("prompt", "[{dir}] > ")
|
viper.SetDefault("prompt", "[{dir}] > ")
|
||||||
@ -84,7 +87,7 @@ func loadConfig() {
|
|||||||
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
if _, ok := err.(viper.ConfigFileNotFoundError); ok {
|
||||||
// Si le fichier n'existe pas, le créer avec les valeurs par défaut
|
// 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...")
|
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)
|
fmt.Fprintln(os.Stderr, "Erreur lors de la création du fichier de configuration:", err)
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Fichier de configuration créé avec succès:", configPath)
|
fmt.Println("Fichier de configuration créé avec succès:", configPath)
|
||||||
@ -132,6 +135,11 @@ func getPrompt() string {
|
|||||||
prompt = blue + prompt + reset
|
prompt = blue + prompt + reset
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.Color == "green" {
|
||||||
|
green := "\033[32m"
|
||||||
|
reset := "\033[0m"
|
||||||
|
prompt = green + prompt + reset
|
||||||
|
}
|
||||||
return prompt
|
return prompt
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user