Skip to content

Commit 03fafa7

Browse files
committed
fix(installer): restore shell theme and plugins from snapshot via RestoreFromSnapshot
1 parent cc01d07 commit 03fafa7

4 files changed

Lines changed: 54 additions & 27 deletions

File tree

internal/cli/snapshot.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -766,5 +766,8 @@ func buildImportConfig(edited *snapshot.Snapshot, dryRun bool) *config.Config {
766766
}
767767
}
768768

769+
cfg.SnapshotShellTheme = edited.Shell.Theme
770+
cfg.SnapshotShellPlugins = edited.Shell.Plugins
771+
769772
return cfg
770773
}

internal/config/config.go

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,13 @@ type Config struct {
8888

8989
SelectedPkgs map[string]bool // set by UI package selector
9090
OnlinePkgs []Package // fetched from packages API
91-
SnapshotTaps []string // from snapshot capture
92-
RemoteConfig *RemoteConfig // fetched from openboot.dev at startup
93-
SnapshotGit *SnapshotGitConfig // from snapshot capture
94-
SnapshotMacOS []RemoteMacOSPref // from snapshot capture
95-
SnapshotDotfiles string // from snapshot capture
91+
SnapshotTaps []string // from snapshot capture
92+
RemoteConfig *RemoteConfig // fetched from openboot.dev at startup
93+
SnapshotGit *SnapshotGitConfig // from snapshot capture
94+
SnapshotMacOS []RemoteMacOSPref // from snapshot capture
95+
SnapshotDotfiles string // from snapshot capture
96+
SnapshotShellTheme string // from snapshot capture
97+
SnapshotShellPlugins []string // from snapshot capture
9698
}
9799

98100
// InstallOptions holds user-supplied inputs set from CLI flags and environment
@@ -118,13 +120,15 @@ type InstallOptions struct {
118120
// InstallState holds runtime values populated during installation.
119121
// Fields are written by installer steps and read by subsequent steps.
120122
type InstallState struct {
121-
SelectedPkgs map[string]bool
122-
OnlinePkgs []Package
123-
SnapshotTaps []string
124-
RemoteConfig *RemoteConfig
125-
SnapshotGit *SnapshotGitConfig
126-
SnapshotMacOS []RemoteMacOSPref
127-
SnapshotDotfiles string
123+
SelectedPkgs map[string]bool
124+
OnlinePkgs []Package
125+
SnapshotTaps []string
126+
RemoteConfig *RemoteConfig
127+
SnapshotGit *SnapshotGitConfig
128+
SnapshotMacOS []RemoteMacOSPref
129+
SnapshotDotfiles string
130+
SnapshotShellTheme string
131+
SnapshotShellPlugins []string
128132
}
129133

130134
// ToInstallOptions extracts the read-only input fields from Config.
@@ -151,13 +155,15 @@ func (c *Config) ToInstallOptions() *InstallOptions {
151155
// ToInstallState extracts the mutable runtime fields from Config.
152156
func (c *Config) ToInstallState() *InstallState {
153157
return &InstallState{
154-
SelectedPkgs: c.SelectedPkgs,
155-
OnlinePkgs: c.OnlinePkgs,
156-
SnapshotTaps: c.SnapshotTaps,
157-
RemoteConfig: c.RemoteConfig,
158-
SnapshotGit: c.SnapshotGit,
159-
SnapshotMacOS: c.SnapshotMacOS,
160-
SnapshotDotfiles: c.SnapshotDotfiles,
158+
SelectedPkgs: c.SelectedPkgs,
159+
OnlinePkgs: c.OnlinePkgs,
160+
SnapshotTaps: c.SnapshotTaps,
161+
RemoteConfig: c.RemoteConfig,
162+
SnapshotGit: c.SnapshotGit,
163+
SnapshotMacOS: c.SnapshotMacOS,
164+
SnapshotDotfiles: c.SnapshotDotfiles,
165+
SnapshotShellTheme: c.SnapshotShellTheme,
166+
SnapshotShellPlugins: c.SnapshotShellPlugins,
161167
}
162168
}
163169

@@ -171,6 +177,8 @@ func (c *Config) ApplyState(s *InstallState) {
171177
c.SnapshotGit = s.SnapshotGit
172178
c.SnapshotMacOS = s.SnapshotMacOS
173179
c.SnapshotDotfiles = s.SnapshotDotfiles
180+
c.SnapshotShellTheme = s.SnapshotShellTheme
181+
c.SnapshotShellPlugins = s.SnapshotShellPlugins
174182
}
175183

176184
type SnapshotGitConfig struct {

internal/installer/plan.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ type InstallPlan struct {
3535

3636
// Shell
3737
InstallOhMyZsh bool
38-
DotfilesURL string // "" = skip dotfiles entirely; any URL = use it (may be DefaultDotfilesURL)
38+
ShellTheme string // ZSH_THEME to restore; empty = leave as-is
39+
ShellPlugins []string // plugins=(...) to restore; nil = leave as-is
40+
DotfilesURL string // "" = skip dotfiles entirely; any URL = use it (may be DefaultDotfilesURL)
3941

4042
// macOS
4143
MacOSPrefs []macos.Preference
@@ -319,9 +321,11 @@ func PlanFromSnapshot(opts *config.InstallOptions, st *config.InstallState) Inst
319321
plan.DotfilesURL = st.SnapshotDotfiles
320322
}
321323

322-
// Shell: attempt Oh-My-Zsh for snapshot restores unless explicitly skipped.
324+
// Shell: restore Oh-My-Zsh and theme/plugins from snapshot unless explicitly skipped.
323325
if opts.Shell != "skip" {
324326
plan.InstallOhMyZsh = true
327+
plan.ShellTheme = st.SnapshotShellTheme
328+
plan.ShellPlugins = st.SnapshotShellPlugins
325329
}
326330

327331
// macOS: convert snapshot preferences to macos.Preference values, unless skipped via flag.

internal/installer/step_shell.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,26 @@ func applyShell(plan InstallPlan, r Reporter) error {
1414
if plan.InstallOhMyZsh {
1515
r.Header("Shell Configuration")
1616
fmt.Println()
17-
if shell.IsOhMyZshInstalled() {
18-
r.Muted("Oh-My-Zsh already installed")
19-
} else {
20-
if err := shell.InstallOhMyZsh(plan.DryRun); err != nil {
21-
return fmt.Errorf("install oh-my-zsh: %w", err)
17+
18+
if plan.ShellTheme != "" || len(plan.ShellPlugins) > 0 {
19+
// Restore mode: install OMZ if missing, then write theme/plugins.
20+
if err := shell.RestoreFromSnapshot(true, plan.ShellTheme, plan.ShellPlugins, plan.DryRun); err != nil {
21+
return fmt.Errorf("restore shell config: %w", err)
2222
}
2323
if !plan.DryRun {
24-
r.Success("Oh-My-Zsh installed")
24+
r.Success(fmt.Sprintf("Shell restored (theme: %s, %d plugins)", plan.ShellTheme, len(plan.ShellPlugins)))
25+
}
26+
} else {
27+
// Fresh install mode: just install OMZ.
28+
if shell.IsOhMyZshInstalled() {
29+
r.Muted("Oh-My-Zsh already installed")
30+
} else {
31+
if err := shell.InstallOhMyZsh(plan.DryRun); err != nil {
32+
return fmt.Errorf("install oh-my-zsh: %w", err)
33+
}
34+
if !plan.DryRun {
35+
r.Success("Oh-My-Zsh installed")
36+
}
2537
}
2638
}
2739
fmt.Println()

0 commit comments

Comments
 (0)