diff options
| author | Kujtim Hoxha <[email protected]> | 2025-05-01 12:48:19 +0200 |
|---|---|---|
| committer | adamdottv <[email protected]> | 2025-05-01 11:07:47 -0500 |
| commit | e4680caebb7235988450f6b1d59da2e46a78e567 (patch) | |
| tree | 94b4a560276748b86c67684b6c3053d587076787 /internal/config | |
| parent | e760d28c5a125f7f4de30cf0491be53e32bb897d (diff) | |
| download | opencode-e4680caebb7235988450f6b1d59da2e46a78e567.tar.gz opencode-e4680caebb7235988450f6b1d59da2e46a78e567.zip | |
some small fixes
Diffstat (limited to 'internal/config')
| -rw-r--r-- | internal/config/config.go | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/internal/config/config.go b/internal/config/config.go index 88f3a1838..eec694450 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -6,6 +6,7 @@ import ( "fmt" "log/slog" "os" + "path/filepath" "strings" "github.com/opencode-ai/opencode/internal/llm/models" @@ -735,16 +736,22 @@ func UpdateTheme(themeName string) error { // Get the config file path configFile := viper.ConfigFileUsed() + var configData []byte if configFile == "" { - // If no config file exists yet, create one with default settings - viper.Set("tui.theme", themeName) - return viper.SafeWriteConfig() - } - - // Read the existing config file - configData, err := os.ReadFile(configFile) - if err != nil { - return fmt.Errorf("failed to read config file: %w", err) + homeDir, err := os.UserHomeDir() + if err != nil { + return fmt.Errorf("failed to get home directory: %w", err) + } + configFile = filepath.Join(homeDir, fmt.Sprintf(".%s.json", appName)) + logging.Info("config file not found, creating new one", "path", configFile) + configData = []byte(`{}`) + } else { + // Read the existing config file + data, err := os.ReadFile(configFile) + if err != nil { + return fmt.Errorf("failed to read config file: %w", err) + } + configData = data } // Parse the JSON @@ -770,7 +777,7 @@ func UpdateTheme(themeName string) error { return fmt.Errorf("failed to marshal config: %w", err) } - if err := os.WriteFile(configFile, updatedData, 0644); err != nil { + if err := os.WriteFile(configFile, updatedData, 0o644); err != nil { return fmt.Errorf("failed to write config file: %w", err) } |
