wasmshell

package
v0.16.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuiltinNames = map[string]bool{
	"ls": true, "cd": true, "pwd": true, "cat": true, "mkdir": true,
	"rm": true, "rmdir": true, "cp": true, "mv": true, "touch": true,
	"echo": true, "head": true, "tail": true, "wc": true, "grep": true,
	"sort": true, "find": true, "tree": true, "clear": true, "help": true,
	"date": true, "whoami": true, "env": true, "export": true, "which": true,
	"type": true, "history": true, "println": true, "basename": true,
	"dirname": true, "realpath": true, "tr": true, "uniq": true,
	"cut": true, "tee": true,
}

BuiltinNames lists all built-in command names.

View Source
var CmdRegistry = map[string]CommandFunc{}

CmdRegistry maps command names to their implementations.

Functions

func AutoCompleteJSON

func AutoCompleteJSON(input string) string

AutoCompleteJSON returns completions as a JSON string.

func DeleteFilePath

func DeleteFilePath(path string) error

DeleteFilePath deletes a file.

func ExpandGlobs

func ExpandGlobs(args []string) []string

ExpandGlobs expands glob patterns in arguments.

func GlobCompletion

func GlobCompletion(prefix string) []string

GlobCompletion returns files matching a glob prefix for tab completion.

func HistorySearch

func HistorySearch(prefix string) []string

HistorySearch searches command history for a prefix.

func JSONResult

func JSONResult(r CmdResult) string

JSONResult marshals a CmdResult to JSON string.

func ListDirEntryJSON

func ListDirEntryJSON(path string) (string, error)

ListDirEntryJSON returns the JSON representation of directory entries.

func ParseRedirects

func ParseRedirects(line string) (string, []string, string, string, string, bool, bool)

ParseRedirects extracts command name, args, and redirect operators from a line. Returns: name, args, stdinFile, stdoutFile, stderrFile, appendStdout, appendStderr

func ReadFileContent

func ReadFileContent(path string) (string, error)

ReadFileContent reads a file and returns its content as a string.

func RecursiveSync

func RecursiveSync(dir string)

RecursiveSync removes deleted files from the store by walking the filesystem. This is a best-effort reconciliation after operations like rm -rf.

func ResetHistory

func ResetHistory()

ResetHistory clears the command history (useful for testing).

func ResolvePath

func ResolvePath(p string) string

ResolvePath expands ~ and makes relative paths absolute against cwd.

func SetShellEnv

func SetShellEnv(e *Env)

SetShellEnv replaces the global shell environment (useful for testing).

func SetStoreWriter

func SetStoreWriter(s StoreWriter)

SetStoreWriter sets the StoreWriter used for persisting files.

func SplitPipeline

func SplitPipeline(input string) []string

SplitPipeline splits a command line by unquoted pipe characters.

func SyncDeleteFile

func SyncDeleteFile(path string) error

SyncDeleteFile removes a file from the filesystem (MEMFS) and syncs to the StoreWriter.

func SyncWriteFile

func SyncWriteFile(path, content string) error

SyncWriteFile writes content to the filesystem (MEMFS) and syncs to the StoreWriter.

func Tokenize

func Tokenize(line string, keepQuotes bool) []string

Tokenize splits a command line into tokens, respecting quotes and escapes.

func WriteFileContent

func WriteFileContent(path, content string) error

WriteFileContent writes content to a file.

Types

type AutoCompleteResult

type AutoCompleteResult struct {
	Completions []string `json:"completions"`
}

AutoCompleteResult holds the JSON response for tab completion.

func AutoComplete

func AutoComplete(input string) AutoCompleteResult

AutoComplete performs tab completion for the given input. It handles: - Command name completion (first token) - File/directory path completion (subsequent tokens) - History search (for empty input or ! commands)

type CmdResult

type CmdResult struct {
	Stdout   string `json:"stdout"`
	Stderr   string `json:"stderr"`
	ExitCode int    `json:"exitCode"`
}

CmdResult holds the result of a command execution.

func ParseAndExecute

func ParseAndExecute(input string) CmdResult

ParseAndExecute is the main entry point for executing a command string. It handles pipes, redirects, and dispatches to the appropriate command.

func RunCommandWithRedirects

func RunCommandWithRedirects(name string, args []string, stdin string, stdoutRedirect *string, stderrRedirect *string, appendStdout bool) CmdResult

RunCommandWithRedirects runs a command with optional redirect support.

type CommandFunc

type CommandFunc func(args []string, stdin string) CmdResult

CommandFunc is the type for all command implementations.

type DirEntry

type DirEntry struct {
	Name string `json:"name"`
	Type string `json:"type"` // "file" or "dir"
	Size int64  `json:"size"`
	Mode uint32 `json:"mode"`
}

DirEntry represents a directory listing entry.

type Env

type Env struct {
	Vars map[string]string
}

Env holds the shell environment variables.

var ShellEnv *Env

ShellEnv holds the global shell environment.

func NewEnv

func NewEnv() *Env

NewEnv creates a new Env with default shell variables.

func (*Env) All

func (e *Env) All() map[string]string

All returns a copy of all environment variables.

func (*Env) Get

func (e *Env) Get(key string) string

Get returns the value of an environment variable, falling back to the OS environment.

func (*Env) Set

func (e *Env) Set(key, value string)

Set sets an environment variable in both the Env map and the OS environment.

type StoreWriter

type StoreWriter interface {
	SaveFile(path, content string)
	DeleteFile(path string)
}

StoreWriter is the interface for persisting file writes/deletes to external storage. In the WASM build, this is backed by IndexedDB. In tests, a no-op is used.

Jump to

Keyboard shortcuts

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