summaryrefslogtreecommitdiff
path: root/internal/config/config.go
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2026-02-22 20:09:33 +0200
committerPaul Buetow <paul@buetow.org>2026-02-22 20:09:33 +0200
commit528a9c0888f1db2449d30bf9c0c8b55fcd3c645c (patch)
treed8891ac02c1e0d873c0caff3ebe29b4ea2a916af /internal/config/config.go
parentd629558394465b8956285edac324d67688ddd2c1 (diff)
Use \$EDITOR as default editor, falling back to vi (task 344)
defaultConfig() now reads the \$EDITOR environment variable for EditCmd so users get their preferred editor automatically without touching the config file. Falls back to "vi" (universally available) when \$EDITOR is unset or empty. A JSON config value still takes precedence over \$EDITOR. Updated tests to: unset \$EDITOR where "vi" fallback is asserted, add TestLoad_editorEnvVar covering the three cases (\$EDITOR unset, \$EDITOR set, JSON override), and remove all stale "hx" references from comments. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'internal/config/config.go')
-rw-r--r--internal/config/config.go22
1 files changed, 16 insertions, 6 deletions
diff --git a/internal/config/config.go b/internal/config/config.go
index 6354d83..04c8302 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -31,11 +31,20 @@ type Config struct {
SyncRepos []string `json:"sync_repos"`
}
-// defaultConfig returns a Config populated with the same defaults as the
-// Ruby reference implementation's Config::DEFAULTS. It calls
-// os.UserHomeDir() so that path fields expand correctly at runtime.
+// defaultConfig returns a Config populated with built-in defaults.
+// EditCmd honours the $EDITOR environment variable and falls back to "vi"
+// when the variable is unset or empty, so users get their preferred editor
+// automatically without touching the config file.
+// It calls os.UserHomeDir() so that path fields expand correctly at runtime.
func defaultConfig() Config {
home, _ := os.UserHomeDir()
+
+ // Prefer $EDITOR; fall back to vi if not set.
+ editCmd := os.Getenv("EDITOR")
+ if editCmd == "" {
+ editCmd = "vi"
+ }
+
return Config{
DataDir: filepath.Join(home, "git", "geheimlager"),
ExportDir: filepath.Join(home, ".geheimlagerexport"),
@@ -43,7 +52,7 @@ func defaultConfig() Config {
KeyLength: 32,
EncAlg: "AES-256-CBC",
AddToIV: "Hello world",
- EditCmd: "hx",
+ EditCmd: editCmd,
GnomeClipboardCmd: "gpaste-client",
MacOSClipboardCmd: "pbcopy",
SyncRepos: []string{"git1", "git2"},
@@ -68,8 +77,9 @@ func expandPathFields(cfg *Config) {
cfg.KeyFile = expandTilde(cfg.KeyFile)
}
-// Load reads ~/.config/geheim.json and merges it over the built-in defaults.
-// Any field present in the JSON file overrides the corresponding default;
+// Load reads ~/.config/foostore.json and merges it over the built-in defaults.
+// Any field present in the JSON file overrides the corresponding default
+// (including edit_cmd, which defaults to $EDITOR or "vi" when unset);
// fields absent from the file keep their default values.
// If the file is missing or contains invalid JSON a warning is printed to
// stderr and the pure defaults are returned.