Documentation
¶
Overview ¶
Package config handles loading and validation of wt configuration.
Configuration is read from ~/.wt/config.toml with environment variable overrides for directory settings.
Configuration Sources (highest priority first) ¶
- Config file settings
- Default values
Key Settings ¶
- checkout.worktree_format: Template for worktree folder names (default: "{repo}-{branch}")
- checkout.base_ref: "local" or "remote" for new branch base (default: "remote")
- checkout.auto_fetch: Fetch from origin before checkout (default: false)
- default_sort: Default sort order for "wt list"
Hooks Configuration ¶
Hooks are defined in [hooks.NAME] sections:
[hooks.vscode]
command = "code {worktree-dir}"
description = "Open VS Code"
on = ["checkout"] # auto-run for checkout command
Hooks with "on" run automatically for matching commands (checkout, pr, prune, merge, all). Hooks without "on" only run via explicit --hook=name flag.
Forge Configuration ¶
The [forge] section configures default forge and pattern-based rules:
[forge] default = "github" [[forge.rules]] pattern = "company/*" type = "gitlab"
The [hosts] section maps custom domains to forge types for self-hosted instances.
Path Validation ¶
Directory paths must be absolute or start with ~ (no relative paths like "." or "..") to avoid confusion about the working directory.
Index ¶
- Constants
- Variables
- func DefaultConfig() string
- func WithConfig(ctx context.Context, cfg *Config) context.Context
- func WithWorkDir(ctx context.Context, dir string) context.Context
- func WorkDirFromContext(ctx context.Context) string
- type CheckoutConfig
- type Config
- type ForgeConfig
- type ForgeRule
- type Hook
- type HooksConfig
- type MergeConfig
- type PreserveConfig
- type PruneConfig
- type ThemeConfig
Constants ¶
const DefaultWorktreeFormat = "{repo}-{branch}"
DefaultWorktreeFormat is the default format for worktree folder names
Variables ¶
var ValidThemeModes = []string{"auto", "light", "dark"}
ValidThemeModes is the list of supported theme modes
var ValidThemeNames = []string{"none", "default", "dracula", "nord", "gruvbox", "catppuccin"}
ValidThemeNames is the list of supported theme presets (families)
Functions ¶
func DefaultConfig ¶ added in v0.4.0
func DefaultConfig() string
DefaultConfig returns the default configuration content.
func WithConfig ¶ added in v0.14.0
WithConfig returns a new context with the config stored in it.
func WithWorkDir ¶ added in v0.14.0
WithWorkDir returns a new context with the working directory stored in it.
func WorkDirFromContext ¶ added in v0.14.0
WorkDirFromContext returns the working directory from context. Falls back to os.Getwd() if not stored or empty.
Types ¶
type CheckoutConfig ¶ added in v0.13.0
type CheckoutConfig struct {
WorktreeFormat string `toml:"worktree_format"` // Template for worktree folder names
BaseRef string `toml:"base_ref"` // "local" or "remote" (default: "remote")
AutoFetch bool `toml:"auto_fetch"` // Fetch from origin before checkout
SetUpstream *bool `toml:"set_upstream"` // Auto-set upstream tracking (default: true)
}
CheckoutConfig holds checkout-related configuration
func (*CheckoutConfig) ShouldSetUpstream ¶ added in v0.14.0
func (c *CheckoutConfig) ShouldSetUpstream() bool
ShouldSetUpstream returns true if upstream tracking should be set (default: false)
type Config ¶
type Config struct {
RegistryPath string `toml:"-"` // Override ~/.wt/repos.json path (for testing)
HistoryPath string `toml:"-"` // Override ~/.wt/history.json path (for testing)
DefaultSort string `toml:"default_sort"` // "created", "repo", "branch" (default: "created")
DefaultLabels []string `toml:"default_labels"` // labels for newly registered repos
Hooks HooksConfig `toml:"-"` // custom parsing needed
Checkout CheckoutConfig `toml:"checkout"` // checkout settings
Forge ForgeConfig `toml:"forge"`
Merge MergeConfig `toml:"merge"`
Prune PruneConfig `toml:"prune"`
Preserve PreserveConfig `toml:"preserve"` // file preservation for new worktrees
Hosts map[string]string `toml:"hosts"` // domain -> forge type mapping
Theme ThemeConfig `toml:"theme"` // UI theme/colors for interactive mode
}
Config holds the wt configuration
func FromContext ¶ added in v0.14.0
FromContext returns the config from context. Returns nil if no config is stored.
func Load ¶
Load reads config from ~/.config/wt/config.toml Returns Default() if file doesn't exist (no error) Returns error only if file exists but is invalid Environment variables override config file values: - WT_THEME overrides theme.name - WT_THEME_MODE overrides theme.mode (auto, light, dark)
func (*Config) GetHistoryPath ¶ added in v0.14.0
GetHistoryPath returns the effective history file path. Returns HistoryPath if set (for testing), otherwise returns default ~/.wt/history.json.
type ForgeConfig ¶ added in v0.8.0
type ForgeConfig struct {
Default string `toml:"default"` // default forge type
DefaultOrg string `toml:"default_org"` // default org for clone
Rules []ForgeRule `toml:"rules"`
}
ForgeConfig holds forge-related configuration
func (*ForgeConfig) GetForgeTypeForRepo ¶ added in v0.8.0
func (c *ForgeConfig) GetForgeTypeForRepo(repoSpec string) string
GetForgeTypeForRepo returns the forge type for a given repo spec (e.g., "org/repo") Matches against rules in order, returns default if no match
func (*ForgeConfig) GetUserForRepo ¶ added in v0.8.0
func (c *ForgeConfig) GetUserForRepo(repoSpec string) string
GetUserForRepo returns the gh/glab username for a repo spec Matches against rules in order, returns empty string if no match (use active account)
type ForgeRule ¶ added in v0.8.0
type ForgeRule struct {
Pattern string `toml:"pattern"` // glob pattern like "n26/*" or "company/*"
Type string `toml:"type"` // "github" or "gitlab"
User string `toml:"user"` // optional: gh/glab username for auth
}
ForgeRule maps a pattern to forge settings
type Hook ¶
type Hook struct {
Command string `toml:"command"`
Description string `toml:"description"`
On []string `toml:"on"` // commands this hook runs on (empty = only via --hook)
}
Hook defines a post-create hook
type HooksConfig ¶
HooksConfig holds hook-related configuration
type MergeConfig ¶
type MergeConfig struct {
Strategy string `toml:"strategy"` // "squash", "rebase", or "merge"
}
MergeConfig holds merge-related configuration
type PreserveConfig ¶ added in v0.19.0
type PreserveConfig struct {
Patterns []string `toml:"patterns"` // Glob patterns matched against file basenames
Exclude []string `toml:"exclude"` // Path segments to exclude (e.g., "node_modules")
}
PreserveConfig holds file preservation settings for worktree creation. Matching git-ignored files are copied from an existing worktree into new ones.
type PruneConfig ¶ added in v0.14.0
type PruneConfig struct {
DeleteLocalBranches bool `toml:"delete_local_branches"`
}
PruneConfig holds prune-related configuration
type ThemeConfig ¶ added in v0.13.0
type ThemeConfig struct {
Name string `toml:"name"` // preset name: "none", "default", "dracula", "nord", "gruvbox", "catppuccin"
Mode string `toml:"mode"` // theme mode: "auto", "light", "dark" (default: "auto")
Primary string `toml:"primary"` // main accent color (borders, titles)
Accent string `toml:"accent"` // highlight color (selected items)
Success string `toml:"success"` // success indicators (checkmarks)
Error string `toml:"error"` // error messages
Muted string `toml:"muted"` // disabled/inactive text
Normal string `toml:"normal"` // standard text
Info string `toml:"info"` // informational text
Nerdfont bool `toml:"nerdfont"` // use nerd font symbols (default: false)
}
ThemeConfig holds theme/color configuration for interactive UI