Documentation
¶
Overview ¶
Package integrate connects hopsesh to the rest of the user's machine: the command-line tool on PATH (for app installs), the user's login environment, and the hopsesh skill for every agent. All are opt-in and reversible, and none ever replaces something hopsesh did not create.
Index ¶
- Constants
- Variables
- func AddToPath() (string, error)
- func AdoptLoginEnv()
- func AdoptLoginPATH()
- func AppCLI() (string, error)
- func LinkPath() string
- func LoginEnv() map[string]string
- func LoginPathHas(dir string) bool
- func LookLoginPath(name string) string
- func MergeShared(path string, merge func([]byte) ([]byte, error)) error
- func RemovePathBlock() error
- func RemoveSkill(dir string, files map[string][]byte, force bool) error
- func SetLoginVars(vars []string)
- func SkillBin() string
- func UninstallCLI() error
- func WriteOwned(path string, b []byte) error
- type CLIStatus
- type Record
- type SkillStatus
Constants ¶
const ( CLIMissing = "missing" // nothing there CLIOurs = "ours" // a link to this app's tool CLIOtherApp = "other-app" // a link into another copy of hopsesh.app CLIDangling = "dangling" // a link whose target is gone (the app moved or was deleted) CLIStandalone = "standalone" // a regular file (install script, go install) CLIForeign = "foreign" // a link somewhere else (e.g. Homebrew) )
States of the hopsesh command: on macOS and Linux a link at ~/.local/bin/hopsesh; on Windows the app's folder (with hopsesh.exe beside the app) on the user's PATH.
const ( Absent = "absent" Current = "current" Stale = "stale" Modified = "modified" Foreign = "foreign" Broken = "broken" )
States of a skill copy.
const RecordFile = recordFile
RecordFile is the install record's name in a skill copy's folder.
const SkillName = "hopsesh"
SkillName is the skill's name and folder.
Variables ¶
var ErrForeign = errors.New("a skill called hopsesh already exists and was not installed by hopsesh")
ErrForeign means a skill called hopsesh exists that hopsesh did not install.
var ErrModified = errors.New("the hopsesh skill was edited after hopsesh installed it")
ErrModified means a copy of the skill was edited by the user.
Functions ¶
func AddToPath ¶
AddToPath appends a marked block that puts ~/.local/bin on PATH to the login-shell profile (only when the user asks). It returns the file it changed.
func AdoptLoginEnv ¶
func AdoptLoginEnv()
AdoptLoginEnv sets each SetLoginVars variable in this process from the login shell when the process does not have it (an app started from Finder), so every part of hopsesh, and the agents it starts, use the folders the user's shell would.
func AdoptLoginPATH ¶ added in v0.6.2
func AdoptLoginPATH()
AdoptLoginPATH puts the login shell's PATH in front of this process's (an app started from Finder or by launchd has only the system folders), so the agents it starts, and the commands they run, find what the user's own shell finds (~/.local/bin, Homebrew, ...). Folders only this process had stay, after them.
func AppCLI ¶
AppCLI is the command-line tool inside the running app bundle, or an error explaining why it cannot be linked (not an app, running from a disk image or a translocated copy).
func LoginEnv ¶
LoginEnv returns PATH and the SetLoginVars variables as an interactive login shell sets them (cached; empty values when it cannot be read).
func LoginPathHas ¶
LoginPathHas reports whether dir is on the PATH a new terminal gets.
func LookLoginPath ¶
LookLoginPath finds a command on the PATH a new terminal gets.
func MergeShared ¶
MergeShared rewrites a shared settings file through merge, keeping a backup of what it replaced (path.hopsesh-backup).
func RemovePathBlock ¶
func RemovePathBlock() error
RemovePathBlock removes the block AddToPath added, if present.
func RemoveSkill ¶
RemoveSkill deletes a copy hopsesh owns unchanged, or any copy with force.
func SetLoginVars ¶
func SetLoginVars(vars []string)
SetLoginVars names the variables (besides PATH) LoginEnv reads; call once at start-up, before the first LoginEnv.
func SkillBin ¶
func SkillBin() string
SkillBin is how agents should run hopsesh: plain "hopsesh" when the user's login shell finds it, otherwise an absolute path (the linked tool, the app's tool, or this program).
func UninstallCLI ¶
func UninstallCLI() error
UninstallCLI removes the link when it points into a hopsesh.app (or is broken), and the PATH block hopsesh added, if any.
func WriteOwned ¶
WriteOwned writes a file hopsesh owns outright (an agent's rules file).
Types ¶
type CLIStatus ¶
type CLIStatus struct {
State string `json:"state"`
Path string `json:"path"` // ~/.local/bin/hopsesh; Windows: the app's hopsesh.exe
Target string `json:"target,omitempty"` // where the link points
AppCLI string `json:"appCli,omitempty"` // the tool inside this app
DirOnPath bool `json:"dirOnPath"` // ~/.local/bin (Windows: the app's folder) is on the login PATH
Resolves string `json:"resolves,omitempty"`
Profile string `json:"profile,omitempty"` // file "Add to PATH" would change
PathLine string `json:"pathLine"` // the line to add to Profile; Windows: the folder
PathAdded bool `json:"pathAdded,omitempty"` // hopsesh's block is in the profile
CanInstall string `json:"cannotInstall,omitempty"`
}
CLIStatus describes the command-line tool link.
func CheckCLI ¶
func CheckCLI() CLIStatus
CheckCLI reports the state of ~/.local/bin/hopsesh without following it.
func InstallCLI ¶
InstallCLI links ~/.local/bin/hopsesh to this app's tool. It replaces only links that hopsesh made (into a hopsesh.app, or broken ones); a standalone copy or someone else's link is replaced only with force, and kept as hopsesh.bak-<time>.
type Record ¶
type Record struct {
Version string `json:"hopseshVersion"`
Files map[string]string `json:"files"` // name → sha256
}
Record is the install record.
type SkillStatus ¶
type SkillStatus struct {
State string `json:"state"`
Dir string `json:"dir"`
Version string `json:"installedVersion,omitempty"`
Changed []string `json:"changedFiles,omitempty"` // files the user edited
// Newer: a newer hopsesh than this one installed it (its files differ from this
// build's); this build leaves it as it is.
Newer bool `json:"newer,omitempty"`
}
SkillStatus is one copy of the skill.
func CheckSkill ¶
func CheckSkill(dir string, files map[string][]byte, version string) SkillStatus
CheckSkill compares the skill in dir with the files this build (version) would write.
func InstallSkill ¶
InstallSkill writes the files to dir. An edited copy, or one hopsesh did not write, is replaced only with force (the old folder is kept as hopsesh.bak-N).