feat: E edits the config file
CI / Checks (pull_request) Successful in 24s
PR title / Conventional title (pull_request) Successful in 2s

E opens your config like e opens a file: in the nvim lazysecrets runs
in, else in $VISUAL or $EDITOR, else in the system's default app. A
missing config is made first, with a link to its docs. Closing the
editor says to restart lazysecrets to use the changes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
kebandClaude Opus 5.5 committed 2026-10-13 12:55:03 +02:00
1 parent 1a5e40a012
commit 765f9f6aea
6 files changed
+86 -6

No files matched your search

+37 -3
View File
@@ -3,6 +3,7 @@ package app
import (
"cmp"
"errors"
"io/fs"
"os"
"os/exec"
"path/filepath"
@@ -13,6 +14,7 @@ import (
"git.kebcloud.no/keb/lazysecrets/internal/browser"
"git.kebcloud.no/keb/lazysecrets/internal/provider"
"git.kebcloud.no/keb/lazysecrets/internal/update"
)
// Opening a repo's file (e): SOPS files with sops edit, which decrypts
@@ -22,9 +24,10 @@ import (
// secret, editors that can open at a line start on its key.
type editDoneMsg struct {
c provider.Container
name string
err error
c provider.Container
name string
config bool // the config file: read at startup
err error
}
// sopsUnchanged is sops edit's exit code when the file wasn't changed.
@@ -93,6 +96,33 @@ func (m *Model) edit() tea.Cmd {
return m.openInEditor(f, finished)
}
// configHeader starts a config file made to be edited.
const configHeader = "# lazysecrets config: " + update.DefaultRepo + "/src/branch/main/docs/config.md\n"
// editConfig opens the user's config file (the first of them), as e
// opens a file, making it if it isn't there yet.
func (m *Model) editConfig() tea.Cmd {
if len(m.configFiles) == 0 {
m.flash = warning("no config file")
return nil
}
path := m.configFiles[0]
if _, err := os.Stat(path); errors.Is(err, fs.ErrNotExist) {
err := os.MkdirAll(filepath.Dir(path), 0o755)
if err == nil {
err = os.WriteFile(path, []byte(configHeader), 0o644)
}
if err != nil {
m.flash = flash{text: "edit config: " + err.Error(), isErr: true}
return nil
}
}
name := filepath.Base(path)
return m.openInEditor(provider.File{Path: path}, func(err error) tea.Msg {
return editDoneMsg{name: name, config: true, err: err}
})
}
// plusLine are editors that open at a line with +N before the file.
var plusLine = map[string]bool{
"vi": true, "vim": true, "nvim": true, "nano": true, "emacs": true, "emacsclient": true,
@@ -142,6 +172,10 @@ func (m *Model) handleEditDone(msg editDoneMsg) tea.Cmd {
m.flash = flash{text: "open " + msg.name + ": " + msg.err.Error(), isErr: true}
return nil
}
if msg.config {
m.flash = done("closed " + msg.name + ": restart lazysecrets to use it")
return nil
}
m.flash = done("closed " + msg.name)
if c, ok := m.containers.Selected(); ok && containerKey(c) == containerKey(msg.c) {
m.hideValue()