alias

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: GPL-3.0 Imports: 6 Imported by: 0

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

View Source
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

func IsValidName(name string) bool

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.

func ByName

func ByName(name string) (Installer, bool)

ByName returns the installer with the given machine name on the current OS, or false if it is unsupported here.

func Detect

func Detect() (Installer, bool)

Detect picks the installer matching the login shell ($SHELL). Returns false when $SHELL is unset or names a shell we do not support, so the caller can fall back to an interactive picker.

Jump to

Keyboard shortcuts

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