shellenv

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package shellenv resolves the shell interpreter used to run agent and workflow shell commands, so run_shell works on every platform.

The whole system emits POSIX commands (ls, grep, cat, rm, pipes, &&, $VAR) and the run_shell safety denylist is POSIX-shaped, so a POSIX shell is always preferred. On Linux/macOS that shell is always present (/bin/sh). On Windows we discover a bash (Git for Windows, MSYS2, or an explicit override) so agents behave identically across platforms. When no POSIX shell exists on a Windows host we fall back to PowerShell so run_shell still works rather than failing outright — behaviour is best-effort there, but the tool remains usable.

Index

Constants

View Source
const EnvOverride = "TOLLECODE_SHELL"

EnvOverride is the environment variable that pins the shell interpreter, taking precedence over discovery. Point it at a bash.exe/sh.exe on Windows.

Variables

This section is empty.

Functions

This section is empty.

Types

type Kind

type Kind int

Kind identifies the interpreter family so callers build the right argv.

const (
	POSIX      Kind = iota // sh/bash: command runs after "-c" (or "-lc" for login)
	PowerShell             // pwsh/powershell.exe: command runs after "-Command"
)

type Shell

type Shell struct {
	Path string
	Kind Kind
}

Shell is a resolved interpreter and its family.

func Lookup

func Lookup(unixDefault string) (Shell, error)

Lookup returns the interpreter to run a command with. On Linux/macOS it is the unixDefault ("sh" or "bash") as a POSIX shell, preserving each call site's historical choice. On Windows it discovers a POSIX bash, falling back to PowerShell, and caches the result.

func (Shell) Args

func (s Shell) Args(login bool) []string

Args returns the argument list that must precede the command string for this shell. login requests a login shell (POSIX only; ignored for PowerShell).

sh, _ := shellenv.Lookup("sh")
cmd := exec.CommandContext(ctx, sh.Path, append(sh.Args(false), command)...)

Jump to

Keyboard shortcuts

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