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 ¶
- func EditorArgv(moduleName, visual, editor string) []string
- func LocalName(remotePath string) string
- func RemoteChanged(rf RemoteFile, exists bool, size int64, modTime time.Time) bool
- func StatRemote(conn *sshcore.Conn, p string) (exists bool, size int64, modTime time.Time, err error)
- func WriteBack(conn *sshcore.Conn, rf RemoteFile, content []byte) error
- type Action
- type Module
- type RemoteFile
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EditorArgv ¶
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 ¶
LocalName is the basename the temp copy gets, so the local editor's filetype detection (extension, well-known names) works as usual.
func RemoteChanged ¶
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 )
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.
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.