executor

package
v1.1.6 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2026 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package executor provides command execution abstractions for the gsh REPL. It supports both bash command execution and gsh script execution, managing environment variables and working directory state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ExecMiddleware

type ExecMiddleware = func(next shinterp.ExecHandlerFunc) shinterp.ExecHandlerFunc

ExecMiddleware is a function that wraps an ExecHandlerFunc to provide additional functionality (e.g., command interception, logging).

type REPLExecutor

type REPLExecutor struct {
	// contains filtered or unexported fields
}

REPLExecutor handles command execution for the REPL using the interpreter's shared sh runner for bash execution and gsh script execution.

func NewREPLExecutor

func NewREPLExecutor(interp *interpreter.Interpreter, logger *zap.Logger, execHandlers ...ExecMiddleware) (*REPLExecutor, error)

NewREPLExecutor creates a new REPLExecutor. The interpreter is required and provides the shared sh runner for bash execution. The logger is optional (can be nil). The execHandlers are optional middleware for intercepting command execution (e.g., for analytics, history, completion).

func (*REPLExecutor) AliasExists

func (e *REPLExecutor) AliasExists(name string) bool

AliasExists returns true if the given name is currently defined as a shell alias in the underlying mvdan/sh runner.

Note: mvdan/sh keeps aliases in an unexported field, so we use reflection.

func (*REPLExecutor) AliasOrFunctionExists added in v1.0.1

func (e *REPLExecutor) AliasOrFunctionExists(name string) bool

AliasOrFunctionExists returns true if the given name is defined as either a shell alias or a shell function. This is useful for syntax highlighting to recognize user-defined commands from config files like .gshenv and .gsh_profile.

func (*REPLExecutor) Close

func (e *REPLExecutor) Close() error

Close cleans up any resources held by the executor.

func (*REPLExecutor) ExecuteBash

func (e *REPLExecutor) ExecuteBash(ctx context.Context, command string) (int, error)

ExecuteBash runs a bash command with output going to stdout/stderr. Returns the exit code and any execution error.

func (*REPLExecutor) ExecuteBashInSubshell

func (e *REPLExecutor) ExecuteBashInSubshell(ctx context.Context, command string) (string, string, int, error)

ExecuteBashInSubshell runs a bash command in a subshell, capturing output. Returns stdout, stderr, exit code, and any execution error.

func (*REPLExecutor) ExecuteGsh

func (e *REPLExecutor) ExecuteGsh(ctx context.Context, script string) error

ExecuteGsh runs a gsh script. Returns any execution error.

func (*REPLExecutor) FunctionExists added in v1.0.1

func (e *REPLExecutor) FunctionExists(name string) bool

FunctionExists returns true if the given name is currently defined as a shell function in the underlying mvdan/sh runner.

Note: mvdan/sh's Funcs field is exported, but we still use reflection for consistency.

func (*REPLExecutor) GetEnv

func (e *REPLExecutor) GetEnv(name string) string

GetEnv gets an environment variable value from the interpreter's runner.

func (*REPLExecutor) GetPwd

func (e *REPLExecutor) GetPwd() string

GetPwd returns the current working directory from the interpreter's runner.

func (*REPLExecutor) Interpreter

func (e *REPLExecutor) Interpreter() *interpreter.Interpreter

Interpreter returns the underlying gsh interpreter. This is useful for advanced use cases that need direct access.

func (*REPLExecutor) RunBashScriptFromReader

func (e *REPLExecutor) RunBashScriptFromReader(ctx context.Context, reader io.Reader, name string) error

RunBashScriptFromReader runs a bash script from an io.Reader.

func (*REPLExecutor) Runner

func (e *REPLExecutor) Runner() *shinterp.Runner

Runner returns the underlying mvdan/sh runner from the interpreter. This is useful for advanced use cases that need direct access.

func (*REPLExecutor) SetEnv

func (e *REPLExecutor) SetEnv(name, value string)

SetEnv sets an environment variable in the interpreter's runner.

Jump to

Keyboard shortcuts

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