Skip to content

Add completion auto-install and uninstall#1488

Draft
mnorth-stripe wants to merge 2 commits intoplugin-completion-protocolfrom
plugin-completion
Draft

Add completion auto-install and uninstall#1488
mnorth-stripe wants to merge 2 commits intoplugin-completion-protocolfrom
plugin-completion

Conversation

@mnorth-stripe
Copy link
Copy Markdown
Contributor

@mnorth-stripe mnorth-stripe commented Mar 15, 2026

Summary

Add a colorized diff preview when stripe completion --install or --uninstall modifies shell config files. Users see the exact changes before approving.

  • Colorized diff renderer (pkg/ansi/diff.go) with line numbers, context lines, multi-hunk support, and dark green/red true-color backgrounds
  • Pure computeAddSentinel/computeRemoveSentinel functions (no I/O) for sentinel block manipulation
  • Inline read → compute → diff → confirm → write flow — no wrapper abstractions
  • Early shell name validation, Long/Example help text, quoted source paths
  • 256-color line number foreground (bright green for adds, desaturated red for removes)
  • True-color (24-bit) line backgrounds that span the full line including gutter

stripe completion --install (new file)

 ~/.zshrc (new file):
 
+    1 +# begin stripe-completion
+    2 +source "/Users/jane/.stripe/stripe-completion.zsh"
+    3 +# end stripe-completion
 
 Apply changes? [y/N]

stripe completion --uninstall (lines removed)

 ~/.zshrc:
 
     1  export PATH=/usr/local/bin:$PATH
     2  alias ll='ls -la'
-    3 -# begin stripe-completion
-    4 -source "/Users/jane/.stripe/stripe-completion.zsh"
-    5 -# end stripe-completion
 
 Apply changes? [y/N]

stripe completion --help

   Short: "Generate bash, zsh, and fish completion scripts",
+  Long:  "Generate shell completion scripts. Use --install to automatically
+          configure your shell profile, or run without flags to generate a
+          script file manually.",
+  Example: `  # Auto-install completions (detects your shell)
+  stripe completion --install
+
+  # Install for a specific shell
+  stripe completion --install --shell zsh
+
+  # Remove installed completions
+  stripe completion --uninstall
+
+  # Generate completion script to stdout
+  stripe completion --shell bash --write-to-stdout`,

Test plan

  • go test ./pkg/ansi/... — 15 diff renderer tests (new file, add/remove/replace, multi-hunk, context capping, line alignment)
  • go test ./pkg/cmd/... — pure function tests for computeAddSentinel/computeRemoveSentinel, readConfigFile, install/uninstall integration tests, confirmation accept/decline, manual remnant warnings
  • golangci-lint passes
  • Colors respect --color off, CLICOLOR=0, non-TTY piping (via ansi.Color(w))

@mnorth-stripe
Copy link
Copy Markdown
Contributor Author

Adds --install and --uninstall flags to `stripe completion` that
automatically write the completion script and configure the user's
shell profile. Detects and warns about pre-existing manual completion
references to avoid double-loading.

Also adds the plugin completion protocol: when a plugin command
receives tab completion requests, the host CLI invokes the plugin
binary with Cobra's __complete protocol and returns the results.

Committed-By-Agent: claude
Show users a line-numbered, colorized diff of proposed changes to their
shell config file before prompting for confirmation. This replaces the
plain-text description that was used previously.

- Add RenderDiff in pkg/ansi for colorized diff output with context
  lines, multi-hunk support, and dark green/red true-color backgrounds
- Refactor sentinel functions into pure compute functions (no I/O)
- Inline read → compute → diff → confirm → write flow in callers
- Remove dead addSentinelBlock/removeSentinelBlock functions
- Add early shell validation, Long/Example help text, quoted source paths
- Delete orphaned pkg/cmd/configdiff.go

Committed-By-Agent: claude
@tomer-stripe
Copy link
Copy Markdown
Collaborator

Do we actually need a colorized diff? I'm unsure if it's meaningfully useful, especially as a default feature.

Also the pr title is confusing me, this isn't auto-installing or uninstalling?

@mnorth-stripe mnorth-stripe marked this pull request as draft March 16, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants