edit

package
v0.0.0-...-f8e75d3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 9, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package edit reproduces editing a remote file in vim/nano/$EDITOR without installing anything remotely: SFTP fetch to a local temp file, the user's own local editor, SFTP writeback. Per docs/ARCHITECTURE.md non-goals it contains no editor logic of its own.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EditorArgv

func EditorArgv(moduleName, visual, editor string) []string

EditorArgv resolves which local editor to run. Invoked as "vim" or "nano", the module runs exactly that; the generic "edit" name defers to $VISUAL, then $EDITOR (split on whitespace, so "code --wait" works), then vi.

func LocalName

func LocalName(remotePath string) string

LocalName is the basename the temp copy gets, so the local editor's filetype detection (extension, well-known names) works as usual.

func RemoteChanged

func RemoteChanged(rf RemoteFile, exists bool, size int64, modTime time.Time) bool

RemoteChanged reports whether the file on the host no longer matches what was fetched. SFTP mtimes have second resolution, so times are compared truncated to seconds.

func StatRemote

func StatRemote(conn *sshcore.Conn, p string) (exists bool, size int64, modTime time.Time, err error)

StatRemote re-checks the file just before writeback so a concurrent remote modification is caught instead of silently overwritten.

func WriteBack

func WriteBack(conn *sshcore.Conn, rf RemoteFile, content []byte) error

WriteBack uploads content to rf.Path. It prefers write-to-temp + posix-rename so a dropped connection mid-transfer never leaves a half-written file (sshcore deliberately never retries SFTP); symlinks and unwritable directories fall back to an in-place write. The original permissions are preserved.

Types

type Action

type Action int

Action is what should happen after the editor exits.

const (
	// ActionWrite: content changed, remote untouched - write it back.
	ActionWrite Action = iota
	// ActionSkipUnchanged: the buffer is byte-identical to what was fetched.
	ActionSkipUnchanged
	// ActionDiscard: the editor exited non-zero (vim's :cq) - the user
	// aborted, nothing may be written.
	ActionDiscard
	// ActionConfirm: content changed but so did the remote file while we
	// were editing; only the user can decide to overwrite.
	ActionConfirm
)

func Decide

func Decide(editorExit int, orig, edited []byte, remoteChanged bool) Action

Decide picks the post-editor action.

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module implements the rapp module interface (see docs/ARCHITECTURE.md). One implementation serves several registered names: "vim" and "nano" run those editors, "edit" defers to $VISUAL/$EDITOR.

func New

func New(name string) Module

func (Module) Name

func (m Module) Name() string

func (Module) Run

func (m Module) Run(ctx context.Context, conn *sshcore.Conn, args []string) error

type RemoteFile

type RemoteFile struct {
	Path      string
	Content   []byte
	Exists    bool
	IsSymlink bool // writeback must not replace the link with a plain file
	Mode      fs.FileMode
	Size      int64
	ModTime   time.Time
}

RemoteFile is the fetched state of the remote path, kept around so the writeback can preserve permissions and detect concurrent modification.

func FetchFile

func FetchFile(conn *sshcore.Conn, p string) (RemoteFile, error)

FetchFile downloads path. A missing file is not an error - it comes back with Exists=false and empty content, and the writeback will create it (editing a new file, like vim does).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址