Documentation
¶
Overview ¶
Package alias installs a shell alias (e.g. `cbr` → `commitbrief`) into the user's shell startup file, cross-platform. It is the OS-level half of `commitbrief setup --alias`; the interactive orchestration lives in internal/setup.
Each supported shell is an Installer. A managed block delimited by blockStart/blockEnd is written into the shell's startup file, so re-running updates the block in place (changing the alias name removes the old one) and lines outside the block are never touched. Conflict detection is best-effort: an executable of the same name on PATH (exec.LookPath) plus a scan of the startup file for an existing alias/function definition outside our block. Shell builtins, functions defined elsewhere, and aliases in a different shell's rc are out of scope (they cannot be detected without invoking the shell).
Index ¶
Constants ¶
const ( // DefaultName is the alias installed when the user accepts the default. DefaultName = "cbr" // Command is what the alias expands to. A bare binary name (not an // absolute path) is deliberate: interactive shells have the install // directory on PATH, and a bare name survives `brew upgrade` / // reinstalls that would invalidate an embedded path. (install-hook // embeds an absolute path because GUI git clients run hooks with a // stripped PATH — that constraint does not apply to a user shell.) Command = "commitbrief" )
Variables ¶
This section is empty.
Functions ¶
func IsValidName ¶
IsValidName reports whether name is a safe shell alias identifier.
Types ¶
type Installer ¶
type Installer interface {
// Name is the machine id: "bash", "zsh", "fish", "powershell", "cmd".
Name() string
// Label is the human-facing name shown in the shell picker.
Label() string
// Target is the resolved destination (file path, or a short
// description for the registry-backed cmd installer).
Target() string
// Conflict returns a non-empty human reason when `alias` is already
// taken outside our managed block — an existing definition in the
// startup surface, or an executable of that name on PATH. Empty means
// the name is free.
Conflict(alias string) (string, error)
// Install writes/updates the managed alias and returns the shell
// reload command the user should run (empty ⇒ "restart your terminal").
// changed is false when the file already held the identical block.
Install(alias string) (changed bool, reloadCmd string, err error)
}
Installer knows how to write a managed alias into one shell's startup surface and how to detect a conflicting prior definition there.
func All ¶
func All() []Installer
All returns the shells we can install an alias for on this Unix-like OS: bash, zsh and fish.