env

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	HomeFromEnv = "VFOX_HOME"
	HookFlag    = "__VFOX_SHELL"
	PidFlag     = "__VFOX_PID"
)
View Source
const Newline = "\n"
View Source
const PathVarName = "PATH"

Variables

This section is empty.

Functions

func CreateDirSymlink(target, link string) error

CreateDirSymlink creates a directory symbolic link on Unix systems

func GetPid added in v0.2.5

func GetPid() int

func GetVfoxHome added in v0.6.6

func GetVfoxHome() string
func IsDirSymlink(path string) bool

IsDirSymlink checks if the given path is a directory symbolic link

func IsHookEnv

func IsHookEnv() bool

func IsMultiplexerEnvironment added in v0.10.0

func IsMultiplexerEnvironment() bool

IsMultiplexerEnvironment detects if the current shell session is running inside a multiplexer or other environment where new panes/windows should have isolated environments. This includes tmux, screen, and potentially other terminal multiplexers.

Supported multiplexers:

  • tmux: Detects via TMUX environment variable

Returns true if running in a multiplexer environment.

func ReadDirSymlink(link string) (string, error)

ReadDirSymlink reads the target of a directory symbolic link

func RemoveDirSymlink(link string) error

RemoveDirSymlink removes a directory symbolic link on Unix systems

Types

type ConfigState added in v1.0.0

type ConfigState struct {

	// Last check time (Unix timestamp in seconds)
	LastCheck int64 `json:"last_check"`

	// Current project config path (to detect directory/project changes)
	CurrentProjectPath string `json:"current_project_path,omitempty"`

	// Config file modification times (Unix timestamps in seconds)
	GlobalMtime  int64 `json:"global_mtime,omitempty"`
	SessionMtime int64 `json:"session_mtime,omitempty"`
	ProjectMtime int64 `json:"project_mtime,omitempty"`

	// Cached PATH value (to detect user-made PATH changes)
	CachedPath string `json:"cached_path,omitempty"`

	// Cached env output (shell script)
	CachedOutput string `json:"cached_output,omitempty"`
	// contains filtered or unexported fields
}

ConfigState tracks the state of configuration files for diff checking

func NewConfigState added in v1.0.0

func NewConfigState(stateFilePath string) *ConfigState

NewConfigState creates a new ConfigState with the given state file path

func (*ConfigState) GetCachedOutput added in v1.0.0

func (s *ConfigState) GetCachedOutput() string

GetCachedOutput returns the cached env output

func (*ConfigState) HasChanged added in v1.0.0

func (s *ConfigState) HasChanged(configPaths map[UseScope]string) (bool, error)

HasChanged checks if any config file has changed based on modification time Returns true if any config file has been modified since last check, or if project directory changed, or if PATH changed

func (*ConfigState) Load added in v1.0.0

func (s *ConfigState) Load() error

Load loads the state from disk

func (*ConfigState) Save added in v1.0.0

func (s *ConfigState) Save() error

Save saves the state to disk

func (*ConfigState) Update added in v1.0.0

func (s *ConfigState) Update(configPaths map[UseScope]string, output string) error

Update updates the state with new config mtimes, current PATH, and cached output

type Envs

type Envs struct {
	Variables Vars
	Paths     *Paths
}

Envs is a struct that contains environment variables and PATH.

func NewEnvs added in v1.0.0

func NewEnvs() *Envs

func (*Envs) Merge added in v1.0.0

func (e *Envs) Merge(envs *Envs)

func (*Envs) MergeByScopePriority added in v1.0.0

func (e *Envs) MergeByScopePriority(envsByScope map[UseScope]*Envs, scopePriority []UseScope)

MergeByScopePriority merges envs from different scopes with proper priority scopePriority: list of scopes in order from HIGHEST to LOWEST priority For example: [Project, Session, Global] means Project has highest priority

NOTE: PATH and Vars are merged differently due to their different semantics: - Paths.Merge appends (first added has higher priority) - Vars.Merge overwrites (last added wins)

So this method handles them separately: - Paths: merged in given order (HIGHEST priority first) - Vars: merged in reverse order (LOWEST priority first, HIGHEST overrides)

type PathFrom added in v0.3.0

type PathFrom int
const (
	EmptyPaths PathFrom = iota
	OsPaths
)

type Paths added in v0.2.5

type Paths struct {
	*util.SortedSet[string]
}

Paths is a slice of PATH.

func NewPaths added in v0.3.0

func NewPaths(from PathFrom) *Paths

NewPaths returns a new Paths. from is the source of the paths. If from is OsPaths, it returns the paths from the environment variable PATH.

func (*Paths) Merge added in v0.3.0

func (p *Paths) Merge(other *Paths) *Paths

func (*Paths) String added in v0.3.0

func (p *Paths) String() string

func (*Paths) ToBinPaths added in v0.5.0

func (p *Paths) ToBinPaths() (*Paths, error)

ToBinPaths returns a BinPaths from Paths which contains only executable files.

type RuntimeEnvContext added in v1.0.0

type RuntimeEnvContext struct {
	UserConfig        *config.Config     // UserConfig holds the user configuration.
	CurrentWorkingDir string             // CurrentWorkingDir is the current working directory.
	PathMeta          *pathmeta.PathMeta // PathMeta holds the path info of the environment.
	RuntimeVersion    string             // RuntimeVersion is the version of vfox
}

RuntimeEnvContext represents the runtime environment context.

func (*RuntimeEnvContext) CleanSystemPaths added in v1.0.0

func (m *RuntimeEnvContext) CleanSystemPaths() *Paths

CleanSystemPaths returns system PATH with all vfox-managed paths removed (prefix match). This ensures the system PATH is clean before adding vfox paths back in priority order.

func (*RuntimeEnvContext) GetLinkDirPathByScope added in v1.0.0

func (m *RuntimeEnvContext) GetLinkDirPathByScope(scope UseScope) string

GetLinkDirPathByScope returns the symlink directory path for the given scope.

func (*RuntimeEnvContext) HttpClient added in v1.0.0

func (m *RuntimeEnvContext) HttpClient() *http.Client

HttpClient creates an HTTP client based on the proxy settings in the user configuration.

func (*RuntimeEnvContext) LoadVfoxTomlByScope added in v1.0.0

func (m *RuntimeEnvContext) LoadVfoxTomlByScope(scope UseScope) (*pathmeta.VfoxToml, error)

LoadVfoxTomlByScope loads the config for the specified scope pathmeta is not aware of scope, but we don't need to track it in VfoxToml

func (*RuntimeEnvContext) LoadVfoxTomlChainByScopes added in v1.0.0

func (m *RuntimeEnvContext) LoadVfoxTomlChainByScopes(scopes ...UseScope) (VfoxTomlChain, error)

LoadVfoxTomlChainByScopes loads configs for multiple scopes and returns a chain Scopes are added in order (first added = lowest priority) Example: LoadVfoxTomlChainByScopes(Global, Session, Project) → Project has highest priority

type UseScope added in v1.0.0

type UseScope int
const (
	Global UseScope = iota
	Project
	Session
)

func (UseScope) String added in v1.0.0

func (s UseScope) String() string

type Vars added in v0.2.5

type Vars map[string]*string

Vars is a map of environment variables

func (Vars) Merge added in v1.0.0

func (v Vars) Merge(vars Vars)

type VfoxTomlChain added in v1.0.0

type VfoxTomlChain []*chainItem

VfoxTomlChain is a chain of VfoxToml configs, supporting multi-config merging

func NewVfoxTomlChain added in v1.0.0

func NewVfoxTomlChain() VfoxTomlChain

NewVfoxTomlChain creates a new config chain

func (*VfoxTomlChain) Add added in v1.0.0

func (c *VfoxTomlChain) Add(config *pathmeta.VfoxToml, useScope UseScope)

Add appends a config to the end of the chain

func (*VfoxTomlChain) AddTool added in v1.0.0

func (c *VfoxTomlChain) AddTool(name, version string)

AddTool adds a tool to all configs in the chain

func (*VfoxTomlChain) GetAllTools added in v1.0.0

func (c *VfoxTomlChain) GetAllTools() pathmeta.ToolVersions

GetAllTools returns all tools after merging

func (*VfoxTomlChain) GetByIndex added in v1.0.0

func (c *VfoxTomlChain) GetByIndex(index int) *pathmeta.VfoxToml

GetByIndex returns the config at the specified index

func (*VfoxTomlChain) GetTomlByScope added in v1.0.0

func (c *VfoxTomlChain) GetTomlByScope(scope UseScope) (*pathmeta.VfoxToml, bool)

GetTomlByScope returns the config and scope for the given scope

func (*VfoxTomlChain) GetToolConfig added in v1.0.0

func (c *VfoxTomlChain) GetToolConfig(name string) (*pathmeta.ToolConfig, UseScope, bool)

GetToolConfig retrieves a tool config (searches by priority) Searches from tail to head (high priority to low priority)

func (*VfoxTomlChain) GetToolVersion added in v1.0.0

func (c *VfoxTomlChain) GetToolVersion(name string) (string, UseScope, bool)

GetToolVersion retrieves only the version of a tool (searches by priority)

func (*VfoxTomlChain) IsEmpty added in v1.0.0

func (c *VfoxTomlChain) IsEmpty() bool

IsEmpty checks if the chain is empty

func (*VfoxTomlChain) Length added in v1.0.0

func (c *VfoxTomlChain) Length() int

Length returns the length of the config chain

func (*VfoxTomlChain) Merge added in v1.0.0

func (c *VfoxTomlChain) Merge() *pathmeta.VfoxToml

Merge merges configs by priority Later configs in the chain override earlier ones (if the same tool exists) Example: [Global, Session, Project] → Project has highest priority

func (*VfoxTomlChain) RemoveTool added in v1.0.0

func (c *VfoxTomlChain) RemoveTool(name string)

RemoveTool removes a tool from all configs in the chain

func (*VfoxTomlChain) Save added in v1.0.0

func (c *VfoxTomlChain) Save() error

Save saves all configs in the chain Calls Save() on each VfoxToml (which won't create files if empty)

Jump to

Keyboard shortcuts

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