setup

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Apr 6, 2026 License: MIT Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultEnvFiles = []string{".env", ".env.local", ".env.development", ".env.development.local"}

DefaultEnvFiles is the default list of env files to handle.

View Source
var DefaultSymlinkDirs = []string{".venv"}

DefaultSymlinkDirs are directories symlinked from the main worktree when they exist. This avoids re-creating heavyweight directories per worktree.

Functions

func AppendInit

func AppendInit(rcPath string, shell Shell) error

AppendInit appends the wtf init line to the RC file.

func CompletionFilePath added in v0.4.0

func CompletionFilePath(shell Shell, homeDir string) string

CompletionFilePath returns the standard user-local completion file path for the given shell.

func DiscoverEnvFiles added in v0.4.2

func DiscoverEnvFiles(rootDir string) ([]string, error)

DiscoverEnvFiles walks rootDir and returns relative paths to all .env* files, including those in subdirectories (e.g. app/.env). Directories like node_modules, .git, and vendor are skipped.

func EvalCondition added in v0.4.0

func EvalCondition(expr string, ctx *ConditionContext) (bool, error)

EvalCondition evaluates a condition expression. Supported forms:

  • "" (empty) → true
  • "branch contains '<value>'"
  • "file exists '<path>'"
  • "env VAR is set"

func InitLine

func InitLine(shell Shell) string

InitLine returns the eval line for the given shell. Uses explicit shell argument like Starship: eval "$(wtf init bash)"

func IsInitPresent

func IsInitPresent(rcPath string) (bool, error)

IsInitPresent checks whether the wtf init line is already in the file.

func Render

func Render(shell Shell, funcs []ShellFunc, cr CompletionRenderer) string

Render emits all shell functions for the given shell. If cr is non-nil, it also appends shell completion scripts.

func WriteCompletionFile added in v0.4.0

func WriteCompletionFile(shell Shell, homeDir string, content string) (string, error)

WriteCompletionFile writes a completion script to the standard user-local path. It creates parent directories as needed.

Types

type CmdExecutor added in v0.4.0

type CmdExecutor interface {
	RunShell(dir, command string) error
	RunInteractive(dir, command string) error
}

CmdExecutor abstracts shell command execution for testability.

type CompletionRenderer added in v0.4.0

type CompletionRenderer func(shell Shell) (string, error)

CompletionRenderer generates a shell completion script for the given shell. Used by Render to optionally append tab-completion support.

type CompletionStatus added in v0.4.0

type CompletionStatus struct {
	Configured bool
	Method     string // "inline", "file", ""
	Path       string // file path if method is "file"
}

CompletionStatus represents whether completions are configured for a shell.

func IsCompletionConfigured added in v0.4.0

func IsCompletionConfigured(shell Shell, rcPath string, homeDir string) (CompletionStatus, error)

IsCompletionConfigured checks if wtf completions are set up for the given shell. It checks two sources: the RC file (inline via "wtf init") and standard completion file locations.

type ConditionContext added in v0.4.0

type ConditionContext struct {
	Branch string
	Dir    string
	GetEnv func(string) string
}

ConditionContext provides context for condition evaluation.

type EnvFileHandler added in v0.4.0

type EnvFileHandler struct {
	Symlink  func(oldname, newname string) error
	CopyFile func(src, dst string) error
}

EnvFileHandler handles env file operations with injectable functions.

func NewEnvFileHandler added in v0.4.0

func NewEnvFileHandler() *EnvFileHandler

NewEnvFileHandler creates an EnvFileHandler with real OS functions.

func (*EnvFileHandler) HandleEnvFiles added in v0.4.0

func (h *EnvFileHandler) HandleEnvFiles(mainDir, targetDir, strategy string, files []string) ([]string, error)

HandleEnvFiles processes env files according to the strategy. Returns the list of files that were actually handled (skips files that don't exist in mainDir or already have a correct symlink at the target).

type Options added in v0.4.2

type Options struct {
	SkipEnv     bool   // skip env file handling
	SkipInstall bool   // skip package manager install
	EnvStrategy string // "symlink" (default), "copy", "none"
}

Options controls which setup steps run after worktree creation.

type PackageManager added in v0.4.0

type PackageManager struct {
	Name       string
	InstallCmd string
	Lockfile   string
}

PackageManager describes a detected package manager.

func DetectPackageManager added in v0.4.0

func DetectPackageManager(dir string) (*PackageManager, error)

DetectPackageManager detects the package manager from lockfiles in dir. Returns nil, nil if no known lockfile is found.

type RCFileManager

type RCFileManager struct {
	HomeDir string
}

RCFileManager handles shell RC file operations.

func NewRCFileManager

func NewRCFileManager() (*RCFileManager, error)

NewRCFileManager returns an RCFileManager using the real home directory.

func (*RCFileManager) RCFilePath

func (m *RCFileManager) RCFilePath(shell Shell) (string, error)

RCFilePath returns the RC file path for the given shell.

type RealCmdExecutor added in v0.4.0

type RealCmdExecutor struct{}

RealCmdExecutor executes shell commands via /bin/sh.

func (*RealCmdExecutor) RunInteractive added in v0.4.0

func (r *RealCmdExecutor) RunInteractive(dir, command string) error

RunInteractive executes a command with full terminal access (stdin/stdout/stderr). Uses the user's login shell with -ic so aliases and shell functions are available.

func (*RealCmdExecutor) RunShell added in v0.4.0

func (r *RealCmdExecutor) RunShell(dir, command string) error

RunShell executes a command string via /bin/sh in the given directory. When stdout is a terminal, output is displayed in a fixed-height scrolling region so long builds don't flood the screen.

type Runner added in v0.4.0

type Runner struct {
	CmdExec    CmdExecutor
	EnvHandler *EnvFileHandler
	Out        io.Writer // progress output (stderr in CLI context)
}

Runner orchestrates project setup.

func NewRunner added in v0.4.0

func NewRunner() *Runner

NewRunner creates a Runner with real implementations.

func (*Runner) RunHooks added in v0.4.0

func (r *Runner) RunHooks(commands []string, dir string) error

RunHooks runs a list of hook commands in the given directory. Hooks run interactively with full terminal access, bypassing the scroll writer.

func (*Runner) RunSetup added in v0.4.0

func (r *Runner) RunSetup(mainDir, targetDir string, opts Options) error

RunSetup runs the setup flow for a new worktree.

  1. Discover and symlink env files (.env, .env.local, …) from mainDir → targetDir
  2. Symlink shared directories (.venv) from mainDir → targetDir
  3. Auto-detect package manager and run install

type Shell

type Shell string

Shell represents a supported shell type.

const (
	Bash Shell = "bash"
	Zsh  Shell = "zsh"
	Fish Shell = "fish"
)

Supported shell types.

func ParseShellName added in v0.4.0

func ParseShellName(name string) (Shell, error)

ParseShellName parses a shell name string into a Shell type.

type ShellDetector

type ShellDetector struct {
	// GetEnv returns the value of an environment variable.
	GetEnv func(string) string
	// ReadParentComm reads the parent process comm file (e.g. /proc/<pid>/comm).
	ReadParentComm func(pid int) (string, error)
}

ShellDetector detects the user's current shell.

func NewShellDetector

func NewShellDetector() *ShellDetector

NewShellDetector returns a ShellDetector using real OS functions.

func (*ShellDetector) Detect

func (d *ShellDetector) Detect(override string) (Shell, error)

Detect determines the current shell. Priority: override arg → $SHELL env → parent process.

type ShellFunc

type ShellFunc struct {
	Name string
	Bash string // bash/zsh share syntax
	Fish string
}

ShellFunc defines a shell function to be emitted by `wtf init`.

func DefaultFuncs

func DefaultFuncs() []ShellFunc

DefaultFuncs returns the default set of shell functions.

Jump to

Keyboard shortcuts

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