completion

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Jan 31, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractPipeContext

func ExtractPipeContext(line string, pos int) (extracted string, newPos int)

ExtractPipeContext extracts the command context after the last pipe. For "cat file | pb", returns ("pb", 3) where 3 is the new position. For "ls -la", returns ("ls -la", 5) unchanged. This allows completers to work correctly with piped commands.

Types

type AgentCompleter

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

AgentCompleter provides AI-assisted completions via ??.

func NewAgentCompleter

func NewAgentCompleter(client *agent.Client) *AgentCompleter

NewAgentCompleter creates a new agent completer.

func (*AgentCompleter) Complete

func (c *AgentCompleter) Complete(ctx context.Context, line string, pos int) (Result, error)

Complete returns AI-assisted completions for ?? inline patterns.

func (*AgentCompleter) Name

func (c *AgentCompleter) Name() string

Name returns the completer name.

type AliasCompleter

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

AliasCompleter completes user-defined aliases and functions.

func NewAliasCompleter

func NewAliasCompleter(provider FunctionProvider) *AliasCompleter

NewAliasCompleter creates a new alias completer.

func (*AliasCompleter) Complete

func (c *AliasCompleter) Complete(ctx context.Context, line string, pos int) (Result, error)

Complete returns completions for aliases and functions. Unlike ExecutableCompleter, this completes anywhere (not just command position) because functions can be arguments to xargs, find -exec, etc.

func (*AliasCompleter) Name

func (c *AliasCompleter) Name() string

Name returns the completer name.

type CobraCompleter

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

CobraCompleter provides completions from Cobra-based CLI tools. It uses background prefetching to avoid blocking on TAB press.

func NewCobraCompleter

func NewCobraCompleter() *CobraCompleter

NewCobraCompleter creates a new Cobra completer.

func (*CobraCompleter) ClearCache

func (c *CobraCompleter) ClearCache()

ClearCache clears the completion cache.

func (*CobraCompleter) Complete

func (c *CobraCompleter) Complete(ctx context.Context, line string, pos int) (Result, error)

Complete returns completions from cache only. Use Prefetch to populate the cache in the background.

func (*CobraCompleter) Name

func (c *CobraCompleter) Name() string

Name returns the completer name.

func (*CobraCompleter) Prefetch

func (c *CobraCompleter) Prefetch(line string, pos int)

Prefetch triggers background fetching of Cobra completions. Call this when the user types a space after a command.

func (*CobraCompleter) SetCacheTTL

func (c *CobraCompleter) SetCacheTTL(ttl time.Duration)

SetCacheTTL sets the cache TTL.

type Completer

type Completer interface {
	// Complete returns completions for the given line and cursor position.
	Complete(ctx context.Context, line string, pos int) (Result, error)

	// Name returns the completer name for logging.
	Name() string
}

Completer provides completions for a given input.

type EnvCompleter

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

EnvCompleter completes environment variable names.

func NewEnvCompleter

func NewEnvCompleter(provider EnvProvider) *EnvCompleter

NewEnvCompleter creates a new environment variable completer. If provider is nil, falls back to os.Environ().

func (*EnvCompleter) Complete

func (c *EnvCompleter) Complete(ctx context.Context, line string, pos int) (Result, error)

Complete returns completions for environment variables. Triggers when the user types $ or ${ followed by variable name prefix.

func (*EnvCompleter) Name

func (c *EnvCompleter) Name() string

Name returns the completer name.

func (*EnvCompleter) SetMaskSensitive

func (c *EnvCompleter) SetMaskSensitive(enabled bool)

SetMaskSensitive enables or disables masking of sensitive env var values.

type EnvProvider

type EnvProvider interface {
	Environ() []string
}

EnvProvider is the interface for getting environment variables from the executor.

type ExecutableCompleter

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

ExecutableCompleter completes executable names from PATH. It is triggered when completing the first word of a command (or after a pipe).

func NewExecutableCompleter

func NewExecutableCompleter() *ExecutableCompleter

NewExecutableCompleter creates a new executable completer.

func (*ExecutableCompleter) Complete

func (c *ExecutableCompleter) Complete(ctx context.Context, line string, pos int) (Result, error)

Complete returns executable completions from PATH. Only completes when in command position (first word or after pipe).

func (*ExecutableCompleter) Name

func (c *ExecutableCompleter) Name() string

Name returns the completer name.

type FileCompleter

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

FileCompleter completes filesystem paths.

func NewFileCompleter

func NewFileCompleter() *FileCompleter

NewFileCompleter creates a new filesystem completer.

func (*FileCompleter) Complete

func (c *FileCompleter) Complete(ctx context.Context, line string, pos int) (Result, error)

Complete returns filesystem completions.

func (*FileCompleter) Name

func (c *FileCompleter) Name() string

Name returns the completer name.

func (*FileCompleter) SetFuzzyMode

func (c *FileCompleter) SetFuzzyMode(enabled bool)

SetFuzzyMode sets whether to return all candidates (for router-level fuzzy filtering).

func (*FileCompleter) SetShowHidden

func (c *FileCompleter) SetShowHidden(show bool)

SetShowHidden toggles hidden file visibility.

type FunctionProvider

type FunctionProvider interface {
	Functions() []string
}

FunctionProvider is the interface for getting function names from the executor.

type Item

type Item struct {
	Value       string // The actual completion value
	Display     string // What to show in the menu (may differ from Value)
	Description string // Optional description
	Icon        string // Nerd Font icon (optional)
	Score       int    // For fuzzy sorting (higher = better match)
}

Item represents a single completion suggestion.

func FuzzyFilter

func FuzzyFilter(items []Item, query string) []Item

FuzzyFilter filters and sorts items by fuzzy match score.

type Kind

type Kind string

Kind represents the type of completion item for icon display.

const (
	KindFile       Kind = "file"
	KindDirectory  Kind = "directory"
	KindExecutable Kind = "executable"
	KindAlias      Kind = "alias" // User-defined functions and aliases (ƒ icon)
	KindEnv        Kind = "env"   // Environment variables ($ icon)
)

type Prefetcher

type Prefetcher interface {
	Prefetch(line string, pos int)
}

Prefetcher is an optional interface for completers that support background prefetching.

type Priority

type Priority int

Priority defines completer ordering (lower = higher priority).

const (
	PriorityToolNative Priority = 100 // Try first for subcommand completion
	PriorityAlias      Priority = 125 // User-defined functions/aliases (before executables)
	PriorityEnv        Priority = 130 // Environment variables ($VAR)
	PriorityExecutable Priority = 150 // Executable names from PATH (command position only)
	PriorityFilesystem Priority = 200 // Fallback for file arguments
	PriorityAgent      Priority = 300 // AI-powered fallback
)

type Result

type Result struct {
	Items  []Item // List of completions
	Prefix string // Common prefix to preserve
}

Result holds completion results from a completer.

type Router

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

Router dispatches completion requests to registered completers.

func NewRouter

func NewRouter() *Router

NewRouter creates a new completion router.

func (*Router) Complete

func (r *Router) Complete(ctx context.Context, line string, pos int) (Result, error)

Complete tries each completer in priority order until one returns results.

func (*Router) Completers

func (r *Router) Completers() []Completer

Completers returns the registered completers for inspection.

func (*Router) Fuzzy

func (r *Router) Fuzzy() bool

Fuzzy returns whether fuzzy filtering is enabled.

func (*Router) Prefetch

func (r *Router) Prefetch(line string, pos int)

Prefetch triggers background prefetching for all completers that support it. Call this when the user types a space after a command.

func (*Router) Register

func (r *Router) Register(c Completer, priority Priority)

Register adds a completer with the given priority. Lower priority values are tried first.

func (*Router) SetFuzzy

func (r *Router) SetFuzzy(enabled bool)

SetFuzzy enables or disables fuzzy filtering of results.

Jump to

Keyboard shortcuts

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