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 --- internal/cli/cli_fish.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'internal/cli') diff --git a/internal/cli/cli_fish.go b/internal/cli/cli_fish.go index b2d3616..0590345 100644 --- a/internal/cli/cli_fish.go +++ b/internal/cli/cli_fish.go @@ -28,14 +28,14 @@ func (c *CLI) cmdFish(stdout io.Writer) int { if err != nil { binaryPath = "foostore" } - script := fishIntegrationScript(binaryPath) + script := FishIntegrationScript(binaryPath) if _, err := io.WriteString(stdout, script); err != nil { return 1 } return 0 } -// fishIntegrationScript returns the complete fish shell integration script for +// FishIntegrationScript returns the complete fish shell integration script for // the given binary path. The script combines the foostore completion rules and // the ge wrapper function so users need only source a single output: // @@ -44,7 +44,13 @@ func (c *CLI) cmdFish(stdout io.Writer) int { // The binary name is extracted from binaryPath (basename without path) and used // wherever "foostore" appears in complete directives, making the script // correct even when the binary is renamed. -func fishIntegrationScript(binaryPath string) string { +// +// This function is exported so cmd/foostore/main.go can short-circuit the +// "fish" subcommand before constructing a CLI — the script is purely static +// and needs no backend, cipher, store, git, or shell initialisation. Avoiding +// that init shaves ~1.8s (KeePass Argon2 KDF) off every interactive fish +// shell startup that sources `foostore fish`. +func FishIntegrationScript(binaryPath string) string { bin := filepath.Base(binaryPath) var b strings.Builder -- cgit v1.2.3