Help us shape the future of Go! Take the 2026 Go Developer Survey

sh

package
v1.11.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package sh runs external tools (kubectl, docker, ssh, ...) with errors that carry their stderr.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Alive

func Alive(pid int) bool

Alive says whether a process with this pid exists.

func Detach

func Detach(cmd *exec.Cmd)

Detach starts cmd in a session of its own, so it outlives rig and a group signal reaches all of it.

func Detached

func Detached(cmd *exec.Cmd)

Detached runs cmd in a session of its own, without the terminal: a background task must not query the terminal, whose answers would land in the TUI's input. KillGroup stops it.

func FreeBytes

func FreeBytes(path string) (uint64, error)

FreeBytes is the space a user can still write on the filesystem holding path.

func Have

func Have(name string) bool

Have reports whether a tool is on PATH.

func Hint

func Hint(text string) string

Hint is what to do about an error a new setup typically hits (a tool not installed, Docker not running, no Kubernetes cluster), "" when it is none of those.

func Interrupt

func Interrupt(pid int) error

Interrupt sends pid SIGINT.

func KillGroup

func KillGroup(cmd *exec.Cmd)

func OwnGroup

func OwnGroup(cmd *exec.Cmd)

OwnGroup puts cmd in a process group of its own, so KillGroup stops what it started too (go test's test binaries).

func StopGroup

func StopGroup(pid int, force bool)

StopGroup asks the process group led by pid to stop (SIGTERM), or forces it (SIGKILL).

func TiedToParent

func TiedToParent(cmd *exec.Cmd)

TiedToParent makes cmd die with this process, even when this process is killed: a port-forward must not outlive the rig that opened it.

func WithHint

func WithHint(text string) string

WithHint is text with Hint's advice after it, when there is any.

Types

type Cmd

type Cmd struct {
	Name  string
	Args  []string
	Dir   string
	Env   []string
	Stdin io.Reader
}

func New

func New(name string, args ...string) *Cmd

func (*Cmd) Attach

func (c *Cmd) Attach(ctx context.Context, stdin io.Reader, stdout, stderr io.Writer) error

Attach runs the command on the given streams (an interactive shell, a live log), or, when the caller asked to capture it, hands the command back to run on the caller's terminal.

func (*Cmd) Exec

func (c *Cmd) Exec(ctx context.Context) *exec.Cmd

Exec is the *exec.Cmd form, for front ends that hand the terminal over (bubbletea's ExecProcess).

func (*Cmd) Lines

func (c *Cmd) Lines(ctx context.Context) (<-chan string, error)

Lines streams stdout line by line until the command exits or ctx ends; the channel then closes.

func (*Cmd) Output

func (c *Cmd) Output(ctx context.Context) ([]byte, error)

Output runs the command and returns stdout; a failure includes the trimmed stderr.

func (*Cmd) Run

func (c *Cmd) Run(ctx context.Context) error

Jump to

Keyboard shortcuts

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