config

package
v1.38.5 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigDir added in v1.21.0

func ConfigDir() string

ConfigDir returns the platform-specific directory for configuration files. On Unix: $XDG_CONFIG_HOME/chop or ~/.config/chop On Windows: %AppData%\chop

func DataDir added in v1.21.0

func DataDir() string

DataDir returns the platform-specific directory for state, logs, and database. On Unix: $XDG_DATA_HOME/chop or ~/.local/share/chop On Windows: %LocalAppData%\chop

func DiscoveryPath added in v1.26.0

func DiscoveryPath() (string, error)

DiscoveryPath returns the path to the discovery file.

func FiltersConfigPath added in v1.6.0

func FiltersConfigPath() string

FiltersConfigPath returns the path to the custom filters file.

func IsSecure added in v1.21.0

func IsSecure(path string) bool

IsSecure checks if the given path is secure (owned by current user or root, and not world-writable). Parent directories are also checked recursively up to the root.

func LoadCustomFilters added in v1.6.0

func LoadCustomFilters() map[string]CustomFilter

LoadCustomFilters reads the custom filters config file. Global filters are trusted only if the config file is secure. Result is cached for the lifetime of the process.

func LoadCustomFiltersFrom added in v1.6.0

func LoadCustomFiltersFrom(path string) map[string]CustomFilter

LoadCustomFiltersFrom reads custom filters from a specific path as untrusted.

func LoadCustomFiltersWithLocal added in v1.6.0

func LoadCustomFiltersWithLocal(cwd string) map[string]CustomFilter

LoadCustomFiltersWithLocal loads global custom filters, then overlays a local .chop-filters.yml from the given directory (if it exists). Global filters are trusted; local ones are NOT. Local filters are merged on top of global ones (local wins on conflict).

func ParseCustomFilters added in v1.6.0

func ParseCustomFilters(data []byte) map[string]CustomFilter

ParseCustomFilters parses YAML bytes into a custom filters map as untrusted.

func Path

func Path() string

Path returns the config file path.

func Validate added in v1.28.0

func Validate(path string) []string

Validate checks a config file for structural issues and returns a list of human-readable error strings. Returns nil if the file is valid.

func ValidateFilters added in v1.28.0

func ValidateFilters(path string) []string

ValidateFilters checks a filters.yml file for issues: invalid YAML, bad regex patterns, and missing exec scripts. Returns nil if everything looks good.

func WriteDiscoveryInfo added in v1.26.0

func WriteDiscoveryInfo(version string) error

WriteDiscoveryInfo writes discovery metadata to ~/.chop/path.json.

Types

type Config

type Config struct {
	Disabled              []string
	Editor                string
	HistoryCompressedOnly bool
}

Config holds user preferences loaded from ~/.config/chop/config.yml.

func Load

func Load() Config

Load reads the config file and returns a Config. Returns defaults if the file doesn't exist or can't be parsed. Result is cached for the lifetime of the process.

func LoadFrom

func LoadFrom(path string) Config

LoadFrom reads config from a specific path. Exported for testing.

func LoadWithLocal added in v1.1.0

func LoadWithLocal(cwd string) Config

LoadWithLocal loads the global config, then overlays a local .chop.yml from the given directory (if it exists). The local disabled list fully replaces the global one.

func (Config) IsDisabled

func (c Config) IsDisabled(command string, args ...string) bool

IsDisabled returns true if the given command and args match an entry in the disabled list. Matching is prefix-based, so a shorter entry disables all commands that start with it.

Matching rules:

  • "git" disables all git subcommands
  • "git diff" disables any "git diff ..." invocation
  • "git diff --cached" disables only that exact flag combination

Call with: IsDisabled("git", "diff", "--cached") or IsDisabled("git", "diff")

type CustomFilter added in v1.6.0

type CustomFilter struct {
	Keep    []string `yaml:"keep"` // regex patterns - only lines matching at least one are kept
	Drop    []string `yaml:"drop"` // regex patterns - lines matching any are removed
	Head    int      `yaml:"head"` // keep only first N lines (applied after keep/drop)
	Tail    int      `yaml:"tail"` // keep only last N lines (applied after keep/drop)
	Exec    string   `yaml:"exec"` // external script: pipe output through this command
	Trusted bool     `yaml:"-"`    // Internal: true if loaded from a trusted source
}

CustomFilter defines a user-configured output filter for a specific command.

func LookupCustomFilter added in v1.6.0

func LookupCustomFilter(filters map[string]CustomFilter, command string, args []string) *CustomFilter

LookupCustomFilter finds a custom filter for the given command and args. It checks "command subcommand" first, then falls back to "command". Keys are stored lowercased (see parseCustomFiltersWithTrust), so lookups are O(1) map accesses.

type CustomFiltersConfig added in v1.6.0

type CustomFiltersConfig struct {
	Filters map[string]CustomFilter `yaml:"filters"`
}

CustomFiltersConfig holds the full filters.yml content.

type DiscoveryInfo added in v1.26.0

type DiscoveryInfo struct {
	Version string `json:"version"`
	Path    string `json:"path"`
}

DiscoveryInfo contains information for AI agents to discover chop.

Jump to

Keyboard shortcuts

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