From 751c82f337f9dc4756846cf7c547d31668d6587d Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 29 Apr 2026 16:02:24 +0300 Subject: Short-circuit `foostore fish` to skip backend init The fish subcommand prints a purely static shell-integration script and needs no backend, cipher, store, git, or shell. Previously cli.New ran in main() before dispatch, triggering the KeePass Argon2 KDF and adding ~1.8s to every interactive fish shell startup that sources the script. Export FishIntegrationScript and dispatch `fish` directly from main() before constructing the CLI. Local timing: `foostore fish` drops from ~1.834s to ~0.003s. Bump version to v0.8.1. Amp-Thread-ID: https://ampcode.com/threads/T-019dd950-11ef-77aa-bb92-810f22601023 Co-authored-by: Amp --- cmd/foostore/main.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'cmd') diff --git a/cmd/foostore/main.go b/cmd/foostore/main.go index 82283da..1e7a184 100644 --- a/cmd/foostore/main.go +++ b/cmd/foostore/main.go @@ -28,6 +28,20 @@ func main() { os.Exit(0) } + // Short-circuit the "fish" subcommand: it emits a purely static shell + // integration script and needs no backend, cipher, store, git, or shell + // initialisation. Skipping cli.New avoids the KeePass Argon2 KDF cost + // (~1.8s), which makes every interactive fish shell startup that sources + // `foostore fish | source` correspondingly faster. + if len(args) == 1 && args[0] == "fish" { + binaryPath, err := os.Executable() + if err != nil { + binaryPath = "foostore" + } + fmt.Print(cli.FishIntegrationScript(binaryPath)) + os.Exit(0) + } + // Cancel the context on SIGINT or SIGTERM so that long-running operations // (fzf, external editors) terminate gracefully rather than being killed hard. ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) -- cgit v1.2.3