completion

package
v1.3.1 Latest Latest
Warning

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

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

Documentation

Overview

Package completion provides tab completion functionality for the gsh REPL.

Package completion provides tab completion functionality for the gsh REPL. It manages completion specifications, integrates with bash's compgen, and provides file and word completion capabilities.

Package completion provides tab completion functionality for the gsh REPL. It manages completion specifications, integrates with bash's compgen, and provides file and word completion capabilities.

Index

Constants

This section is empty.

Variables

View Source
var OsReadDir = os.ReadDir

OsReadDir is a variable that can be overridden for testing.

Functions

func GetFileCompletions added in v1.1.6

func GetFileCompletions(prefix string, currentDirectory string) []string

GetFileCompletions returns file completions for the given prefix in the current directory.

func NewCompgenCommandHandler

func NewCompgenCommandHandler(runner *interp.Runner) func(next interp.ExecHandlerFunc) interp.ExecHandlerFunc

NewCompgenCommandHandler creates a new ExecHandler for the compgen command.

func NewCompleteCommandHandler added in v1.1.6

func NewCompleteCommandHandler(specRegistry *SpecRegistry) func(next interp.ExecHandlerFunc) interp.ExecHandlerFunc

NewCompleteCommandHandler creates a new ExecHandler for the complete command.

func SplitPreservingQuotes added in v1.1.6

func SplitPreservingQuotes(line string) []string

SplitPreservingQuotes splits a command line into words while preserving quotes.

Types

type CompletionFunction

type CompletionFunction struct {
	Name   string
	Runner *interp.Runner
}

CompletionFunction represents a bash completion function.

func NewCompletionFunction

func NewCompletionFunction(name string, runner *interp.Runner) *CompletionFunction

NewCompletionFunction creates a new CompletionFunction.

func (*CompletionFunction) Execute

func (f *CompletionFunction) Execute(ctx context.Context, args []string) ([]string, error)

Execute runs the completion function with the given arguments.

type CompletionManager added in v1.1.6

type CompletionManager = SpecRegistry

CompletionManager is an alias for SpecRegistry for backward compatibility.

func NewCompletionManager added in v1.1.6

func NewCompletionManager() *CompletionManager

NewCompletionManager creates a new CompletionManager (alias for NewSpecRegistry).

type CompletionSpec

type CompletionSpec struct {
	Command string
	Type    CompletionType
	Value   string   // function name or wordlist
	Options []string // additional options like -o dirname
}

CompletionSpec represents a completion specification for a command.

type CompletionType

type CompletionType string

CompletionType represents the type of completion.

const (
	// WordListCompletion represents word list based completion (-W option).
	WordListCompletion CompletionType = "W"
	// FunctionCompletion represents function based completion (-F option).
	FunctionCompletion CompletionType = "F"
)

type Provider

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

Provider implements the CompletionProvider interface for the REPL input. It parses user input and routes completion requests to the appropriate source (specs, files, commands, macros, etc.)

func NewProvider

func NewProvider(runnerProvider RunnerProvider) *Provider

NewProvider creates a new completion Provider.

func (*Provider) GetCompletions

func (p *Provider) GetCompletions(line string, pos int) []string

GetCompletions returns completion suggestions for the current input line.

func (*Provider) GetHelpInfo

func (p *Provider) GetHelpInfo(line string, pos int) string

GetHelpInfo returns help information for special commands like #! and #/.

func (*Provider) RegisterSpec

func (p *Provider) RegisterSpec(spec CompletionSpec)

RegisterSpec adds or updates a completion specification for a command.

func (*Provider) UnregisterSpec

func (p *Provider) UnregisterSpec(command string)

UnregisterSpec removes a completion specification for a command.

type RunnerProvider

type RunnerProvider interface {
	// Runner returns the underlying mvdan/sh runner.
	Runner() *interp.Runner
	// GetPwd returns the current working directory.
	GetPwd() string
}

RunnerProvider is an interface for getting the shell runner and current directory. This allows the completion provider to work with different executor implementations.

type SpecRegistry

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

SpecRegistry stores and executes command completion specifications. It manages specs like "git completes with add/commit/push" and executes them.

func NewSpecRegistry

func NewSpecRegistry() *SpecRegistry

NewSpecRegistry creates a new SpecRegistry.

func (*SpecRegistry) AddSpec

func (r *SpecRegistry) AddSpec(spec CompletionSpec)

AddSpec adds or updates a completion specification.

func (*SpecRegistry) ExecuteCompletion

func (r *SpecRegistry) ExecuteCompletion(ctx context.Context, runner *interp.Runner, spec CompletionSpec, args []string) ([]string, error)

ExecuteCompletion executes a completion specification for a given command line and returns the list of possible completions.

func (*SpecRegistry) GetSpec

func (r *SpecRegistry) GetSpec(command string) (CompletionSpec, bool)

GetSpec retrieves a completion specification.

func (*SpecRegistry) ListSpecs

func (r *SpecRegistry) ListSpecs() []CompletionSpec

ListSpecs returns all completion specifications.

func (*SpecRegistry) RemoveSpec

func (r *SpecRegistry) RemoveSpec(command string)

RemoveSpec removes a completion specification.

Directories

Path Synopsis
Package completers provides specialized completion sources for different types of input.
Package completers provides specialized completion sources for different types of input.

Jump to

Keyboard shortcuts

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