Skip to content

Commit 8d22c1f

Browse files
feat(config,macos): add SnapshotMacOSPref and InferPreferenceType
Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
1 parent 3c91e76 commit 8d22c1f

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

internal/config/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ type Config struct {
4343

4444
SnapshotShell *SnapshotShellConfig
4545
SnapshotGit *SnapshotGitConfig
46+
SnapshotMacOS []SnapshotMacOSPref
4647
SnapshotDotfiles string
4748
DotfilesURL string
4849
PostInstall string
@@ -59,6 +60,13 @@ type SnapshotGitConfig struct {
5960
UserEmail string
6061
}
6162

63+
type SnapshotMacOSPref struct {
64+
Domain string
65+
Key string
66+
Value string
67+
Desc string
68+
}
69+
6270
type RemoteConfig struct {
6371
Username string `json:"username"`
6472
Slug string `json:"slug"`

internal/macos/macos.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,36 @@ var DefaultPreferences = []Preference{
5050
{"com.apple.TimeMachine", "DoNotOfferNewDisksForBackup", "bool", "true", "Don't prompt for Time Machine on new disks"},
5151
}
5252

53+
func InferPreferenceType(value string) string {
54+
switch strings.ToLower(value) {
55+
case "true", "false", "1", "0", "yes", "no":
56+
return "bool"
57+
}
58+
allDigits := true
59+
for _, c := range value {
60+
if c < '0' || c > '9' {
61+
allDigits = false
62+
break
63+
}
64+
}
65+
if allDigits && value != "" {
66+
return "int"
67+
}
68+
if strings.Contains(value, ".") {
69+
allNumeric := true
70+
for _, c := range strings.ReplaceAll(value, ".", "") {
71+
if c < '0' || c > '9' {
72+
allNumeric = false
73+
break
74+
}
75+
}
76+
if allNumeric {
77+
return "float"
78+
}
79+
}
80+
return "string"
81+
}
82+
5383
func expandHome(path string) string {
5484
if strings.HasPrefix(path, "~/") {
5585
home, err := os.UserHomeDir()

0 commit comments

Comments
 (0)