shell

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package shell is the binary's door to every external command that is not git: a tracker CLI, a project's driver, a pager, an editor, the OS opener. gitx stays separate because its reads mirror bin/f10-load-project.sh's git calls; this is everything that script never runs.

Both entry points are variables so tests can substitute them - nothing here should launch a browser or block on a pager during `go test`.

Index

Constants

This section is empty.

Variables

View Source
var Capture = func(ctx context.Context, dir, name string, args ...string) (Result, error) {
	return run(ctx, dir, nil, name, args...)
}

Capture runs name in dir and collects its output. A non-zero exit is a Result, not an error: the driver contract reserves an exit code with a meaning, so classifying codes belongs to the caller. Only a command that could not start at all is an error here.

View Source
var CaptureInput = func(ctx context.Context, dir, input, name string, args ...string) (Result, error) {
	return run(ctx, dir, strings.NewReader(input), name, args...)
}

CaptureInput is Capture with input on the command's stdin: a driver's write verb reads the task it creates from there.

View Source
var Has = func(name string) bool {
	_, err := exec.LookPath(name)

	return err == nil
}

Has reports whether name is on PATH.

View Source
var Passthrough = func(ctx context.Context, dir, name string, args ...string) error {
	cmd := exec.CommandContext(ctx, name, args...)
	cmd.Dir = dir
	cmd.Stdin, cmd.Stdout, cmd.Stderr = os.Stdin, os.Stdout, os.Stderr

	return cmd.Run()
}

Passthrough runs name in dir wired straight to this process's streams. A pager, an editor and `gh --web` all want the terminal, not a buffer.

View Source
var Pipe = func(ctx context.Context, dir, input, name string, args ...string) error {
	cmd := exec.CommandContext(ctx, name, args...)
	cmd.Dir = dir
	cmd.Stdin = strings.NewReader(input)
	cmd.Stdout, cmd.Stderr = os.Stdout, os.Stderr

	return cmd.Run()
}

Pipe runs name with input on its stdin and this process's terminal on its output - what a pager needs, and the one case where f10 both holds the text and wants someone else to display it.

Functions

func Editor

func Editor() []string

Editor is the editor to hand a local file to: the usual two variables, then the OS opener. Values carry arguments ("code -w"), so callers split on fields rather than exec'ing the string.

func Opener

func Opener() string

Opener is the OS's "open this thing" command, or "" where there is none. A url and a file both go through it.

Types

type Result

type Result struct {
	Stdout string
	Stderr string
	Code   int
}

A Result is one finished command: its trimmed streams and its exit code.

Jump to

Keyboard shortcuts

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