xdg

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 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

Overview

Package xdg provides Neovim-inspired XDG Base Directory path resolution for TaskSmith.

Modeled after Neovim's stdpath() and NVIM_APPNAME conventions, this package resolves user-level directories for configuration, persistent data, local state, cache, and ephemeral runtime files (such as Unix domain sockets and lockfiles).

Application Name (TASKSMITH_APPNAME)

All application directories are scoped by the application name returned by AppName, which defaults to "tasksmith". Users and test harnesses can override this name via the TASKSMITH_APPNAME environment variable (analogous to NVIM_APPNAME in Neovim) to run isolated profiles side by side. Path traversal components ("..") and absolute paths in TASKSMITH_APPNAME are rejected and fall back to "tasksmith".

Directory Types (VarType / stdpath equivalents)

  • VarTypeConfig ("config"): User configuration files ($XDG_CONFIG_HOME/<appname>, defaulting to ~/.config/<appname> on Unix or %LOCALAPPDATA%\<appname> on Windows).
  • VarTypeData ("data"): Persistent application data and workspace repositories ($XDG_DATA_HOME/<appname>, defaulting to ~/.local/share/<appname> on Unix or %LOCALAPPDATA%\<appname> on Windows).
  • VarTypeState ("state"): Persistent local state and logs ($XDG_STATE_HOME/<appname>, defaulting to ~/.local/state/<appname> on Unix or %LOCALAPPDATA%\<appname> on Windows).
  • VarTypeCache ("cache"): Non-essential cached data ($XDG_CACHE_HOME/<appname>, defaulting to ~/.cache/<appname> on Unix or %TEMP%\<appname> on Windows).
  • VarTypeRuntime ("run"): Ephemeral runtime files such as IPC sockets and lockfiles. When $XDG_RUNTIME_DIR is set, Home resolves to $XDG_RUNTIME_DIR/<appname>. When $XDG_RUNTIME_DIR is unset (common on macOS and headless environments), Home falls back to <StateHome>/run (i.e. $XDG_STATE_HOME/<appname>/run).

Workspace, Log, and Socket Helpers

  • WorkspacesHome and WorkspaceDir resolve deterministic per-workspace data directories under <DataHome>/workspaces/<sha256-prefix>.
  • LogsDir and LogFilePath resolve log files under <StateHome>/logs (following Neovim's stdpath("log") convention under the state directory).
  • SocketPath resolves IPC socket and lockfile paths inside the runtime directory.

Index

Constants

View Source
const DefaultAppName = "tasksmith"

DefaultAppName is the default application directory name when TASKSMITH_APPNAME is unset or invalid.

Variables

This section is empty.

Functions

func AppName

func AppName() string

AppName returns the active application name, defaulting to "tasksmith" unless overridden by a valid TASKSMITH_APPNAME environment variable.

func BuiltinDir

func BuiltinDir(subdirs ...string) (string, error)

func ClearCache

func ClearCache()

ClearCache clears the cached XDG base directory paths and reloads TASKSMITH_APPNAME.

func GetVar

func GetVar(varType VarType) string

GetVar returns the base XDG directory path for the given VarType before appending the application name.

func HistoryDir

func HistoryDir() (string, error)

HistoryDir returns the directory path for persistent history files (<StateHome>/history), mirroring LogsDir() under XDG_STATE_HOME.

func HistoryFilePath

func HistoryFilePath(filename string) (string, error)

HistoryFilePath returns the full path for a given history filename within HistoryDir().

func Home

func Home(key VarType) (string, error)

Home returns the application's base directory for the given VarType. For VarTypeConfig, VarTypeData, VarTypeState, and VarTypeCache, it returns "<GetVar(key)>/<AppName()>". For VarTypeRuntime, it returns "$XDG_RUNTIME_DIR/<AppName()>" when XDG_RUNTIME_DIR is set, or "<Home(VarTypeState)>/run" when XDG_RUNTIME_DIR is unset.

func LogFilePath

func LogFilePath(filename string) (string, error)

LogFilePath returns the full path for a given log filename within LogsDir().

func LogsDir

func LogsDir() (string, error)

LogsDir returns the directory path for application logs (<StateHome>/logs), following Neovim's stdpath("log") convention under XDG_STATE_HOME.

func RunWithTestEnv

func RunWithTestEnv(m *testing.M, appName string)

RunWithTestEnv executes a test suite within an isolated temporary XDG environment.

func SetTestEnv

func SetTestEnv(tmpDir string, appName string)

SetTestEnv configures all XDG environment variables and TASKSMITH_APPNAME to use a temporary directory and refreshes the cache.

func SocketPath

func SocketPath(name string) (string, error)

SocketPath returns the full path for an ephemeral socket or lockfile (such as "brain.sock" or "brain.lock") inside the application's runtime directory.

func SubCacheDir

func SubCacheDir(subdirs ...string) (string, error)

SubCacheDir returns a subdirectory within the application's cache directory.

func SubConfigDir

func SubConfigDir(subdirs ...string) (string, error)

SubConfigDir returns a subdirectory within the application's configuration directory.

func SubDataDir

func SubDataDir(subdirs ...string) (string, error)

SubDataDir returns a subdirectory within the application's data directory.

func SubRuntimeDir

func SubRuntimeDir(subdirs ...string) (string, error)

SubRuntimeDir returns a subdirectory within the application's runtime directory.

func SubStateDir

func SubStateDir(subdirs ...string) (string, error)

SubStateDir returns a subdirectory within the application's state directory.

func Subdir

func Subdir(key VarType, subdirs ...string) (string, error)

Subdir returns a subdirectory within the application's base directory for the given VarType.

func UserResourceDirs

func UserResourceDirs() []string

func WorkspaceDir

func WorkspaceDir(key string) (string, error)

WorkspaceDir returns a deterministic directory path for a given workspace key. The directory is located inside WorkspacesHome() and named after the 16-hex-character prefix (first 8 bytes) of the SHA-256 digest of key.

func WorkspacesHome

func WorkspacesHome() (string, error)

WorkspacesHome returns the root directory for all workspaces (<DataHome>/workspaces).

Types

type VarType

type VarType int

VarType represents a category of XDG Base Directory (analogous to Neovim's stdpath types).

const (
	// VarTypeConfig represents the XDG_CONFIG_HOME directory.
	VarTypeConfig VarType = iota
	// VarTypeData represents the XDG_DATA_HOME directory.
	VarTypeData
	// VarTypeState represents the XDG_STATE_HOME directory.
	VarTypeState
	// VarTypeCache represents the XDG_CACHE_HOME directory.
	VarTypeCache
	// VarTypeRuntime represents the XDG_RUNTIME_DIR directory for ephemeral runtime files.
	VarTypeRuntime
)

Jump to

Keyboard shortcuts

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