Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,5 +398,32 @@ func removeEnvironmentFromConfig(config *Config, name string) error {

// Remove environment by copying elements
config.Environments = append(config.Environments[:index], config.Environments[index+1:]...)

// Clear last selected if it was the removed environment
if config.LastSelected == name {
config.LastSelected = ""
}

return nil
}

// updateLastSelected updates the last selected environment in the configuration
func updateLastSelected(config *Config, envName string) {
// Only update if the environment exists
if _, exists := findEnvironmentByName(*config, envName); exists {
config.LastSelected = envName
}
}

// getLastSelectedIndex returns the index of the last selected environment, or 0 if not found
func getLastSelectedIndex(config Config) int {
if config.LastSelected == "" {
return 0 // Default to first environment
}

if index, exists := findEnvironmentByName(config, config.LastSelected); exists {
return index
}

return 0 // Default to first environment if last selected not found
}
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ type Environment struct {
// Config represents the complete configuration with all environments
type Config struct {
Environments []Environment `json:"environments"`
LastSelected string `json:"last_selected,omitempty"`
Settings *ConfigSettings `json:"settings,omitempty"`
}

Expand Down Expand Up @@ -729,6 +730,13 @@ func runDefaultWithOverride(envName string, claudeArgs []string, keyVarOverride
if err != nil {
return fmt.Errorf("environment selection failed: %w", err)
}

// Save last selected environment
updateLastSelected(&config, selectedEnv.Name)
if err := saveConfig(config); err != nil {
// Non-fatal error - continue with execution but log warning
fmt.Fprintf(os.Stderr, "Warning: failed to save last selected environment: %v\n", err)
}
}

// Apply one-run override if provided
Expand Down
Loading
Loading