Documentation
¶
Overview ¶
Package editor provides functionality for opening external editors.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Command ¶ added in v1.9.0
Command builds the *exec.Cmd that opens tmpFile in the user's editor. It resolves VISUAL then EDITOR, falling back to notepad on Windows or vi on other platforms, and invokes through the shell (`sh -c 'editor "$1"' sh tmpFile`) so that quoting and arguments behave exactly like Git does: the temp-file path is passed as $1 so an $EDITOR that itself carries flags or a space-containing path is expanded by the shell (e.g. "code --wait" or "/Applications/Visual Studio Code.app/.../code").
It does NOT wire Stdin/Stdout/Stderr, so the caller (the CLI, or the TUI via tea.ExecProcess) owns the terminal handoff. This is the single command builder both the CLI editor and the TUI's $EDITOR handoff share, so they cannot diverge on VISUAL→EDITOR precedence, shell quoting, or the OS fallback.
func Normalize ¶ added in v1.9.0
Normalize applies the round-trip-lossless rule to the editor's read-back (result) given the exact content that was written into the tmpfile.
Editors typically auto-append a single trailing newline to a buffer that did not already end with one. We reverse ONLY that editor-added newline: if the original content did not end with a newline, a single trailing newline (Unix "\n" or Windows "\r\n") is stripped from the read-back. A trailing newline the value carried in (PEM keys, JSON, ...) is preserved, so opening a value and saving it untouched is byte-identical — which the callers then detect and report as a no-op change.