util

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AtomicWriteFile added in v1.1.45

func AtomicWriteFile(path string, data []byte, defaultMode os.FileMode) error

AtomicWriteFile writes data to path via a temp file in the same directory, fsync's it, and renames it into place. If path already exists, the existing file's mode is preserved; otherwise defaultMode is used.

This avoids two failure modes of os.WriteFile(path, data, mode):

  1. A crash between O_TRUNC and the final write leaves the user's source file truncated/empty.
  2. The hard-coded mode silently downgrades 0755 scripts and 0600 secrets to 0644.

See locks.md S4.

func FormatToolDetail added in v1.1.91

func FormatToolDetail(text, baseDir string) string

FormatToolDetail prepares a tool detail string for display. It relativizes absolute paths under baseDir. No truncation — the rendering layer handles width (TUI auto-wraps, IM sends as-is).

func RelativizePaths added in v1.1.34

func RelativizePaths(text, baseDir string) string

RelativizePaths replaces absolute paths under baseDir with relative paths ("./"). It handles two cases:

  • baseDir + separator + suffix → "./" + suffix
  • baseDir as an exact standalone token → "."

The second case uses boundary checking to avoid false matches (e.g. "/Users/proj" should not match inside "/Users/proj-backup").

func Truncate

func Truncate(s string, maxRunes int) string

Truncate truncates a string to maxRunes runes, appending "..." if truncated. Uses []rune to avoid UTF-8 multi-byte truncation.

Types

type ShellSpec

type ShellSpec struct {
	Path string
	Args []string
	Name string
}

func DetectShell

func DetectShell() (ShellSpec, error)

func NewShellCommand

func NewShellCommand(command string) (*exec.Cmd, ShellSpec, error)

func NewShellCommandContext

func NewShellCommandContext(ctx context.Context, command string) (*exec.Cmd, ShellSpec, error)

Jump to

Keyboard shortcuts

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