config

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package config reads what the desktop app writes: the runtime config (`zennotes.config.json`, where the known vaults and saved servers live) and the portable preferences (`config.toml`). It never writes the former; zn follows the app, it does not steer it.

Index

Constants

View Source
const AppConfigFile = "zennotes.config.json"

AppConfigFile is the runtime config the desktop app maintains.

View Source
const DefaultConfigTOML = `` /* 1848-byte string literal not displayed */

DefaultConfigTOML is the commented starter file `zn config` writes when no config.toml exists yet. Every key matches the desktop app's names.

Variables

View Source
var ErrNoVault = errors.New("No vault is set up for zn yet. Run `zn setup` for a guided start, or one of: `zn init ~/Notes` (create a vault), `zn vault add <folder>` (use an existing one), `zn connect <server-url>` (a ZenNotes server). Opening a vault in the ZenNotes app works too.")

ErrNoVault says nothing names a vault at all.

View Source
var ErrNoWorkspace = errors.New("no saved vault or server has that name")

ErrNoWorkspace says a name matches nothing zn saved.

Functions

func ConfigTomlPath

func ConfigTomlPath() string

ConfigTomlPath is the portable preferences file.

func CredentialsPath

func CredentialsPath() string

CredentialsPath is where server tokens live (mode 0600).

func CustomThemesDir added in v0.3.0

func CustomThemesDir() string

CustomThemesDir is where the desktop app keeps user-authored themes, one folder each, next to config.toml.

func DefaultServerName

func DefaultServerName(baseURL string) string

DefaultServerName names a server after its host: notes.example.com, or localhost for a local address.

func DeleteToken

func DeleteToken(baseURL string) error

DeleteToken forgets a server token.

func ExpandHome

func ExpandHome(target string) string

ExpandHome turns `~` and `~/x` into absolute paths.

func LoadToken

func LoadToken(baseURL string) string

LoadToken is the stored token for a server URL, or "".

func MCPInstructionsPath

func MCPInstructionsPath() string

MCPInstructionsPath is where a user override of the MCP instructions lives.

func PortableConfigDir

func PortableConfigDir() string

PortableConfigDir is where `config.toml` lives: an XDG-style location the user can sync. Deliberately NOT UserDataDir.

func ResolveVaultRoot

func ResolveVaultRoot(selector string) (string, error)

ResolveVaultRoot picks the vault root: an explicit selector, else ZENNOTES_VAULT, else the app's active vault.

func ResolveVaultSelector

func ResolveVaultSelector(selector string) (string, error)

ResolveVaultSelector resolves a `--vault` selector: a known vault name first (case-insensitive), then a directory path. Errors name the available vaults so a typo is self-correcting.

func SaveToken

func SaveToken(baseURL, token string) error

SaveToken stores a server token, replacing any previous one.

func SaveWorkspaces

func SaveWorkspaces(ws Workspaces) error

SaveWorkspaces writes the list atomically.

func UserDataDir

func UserDataDir() string

UserDataDir mirrors Electron's `app.getPath('userData')` for the product name "ZenNotes". ZENNOTES_CONFIG_DIR overrides it, for tests and automation.

func VaultRootFromConfig

func VaultRootFromConfig() string

VaultRootFromConfig is the vault the app last opened, or "".

func WorkspacesPath

func WorkspacesPath() string

WorkspacesPath is where zn's vault and server list lives.

Types

type ActiveWorkspace

type ActiveWorkspace struct {
	// Kind is "local" or "remote".
	Kind      string
	Root      string
	BaseURL   string
	Name      string
	ProfileID string
	AuthToken string
}

ActiveWorkspace is what the desktop app currently has open.

func ActiveWorkspaceFromConfig

func ActiveWorkspaceFromConfig() ActiveWorkspace

ActiveWorkspaceFromConfig reads the workspace the app has open. The app keeps server tokens in the OS secret store, so the token here is only a legacy plaintext one; callers layer ZENNOTES_REMOTE_TOKEN on top.

type KnownVault

type KnownVault struct {
	Root         string `json:"root"`
	Name         string `json:"name"`
	LastOpenedAt *int64 `json:"lastOpenedAt"`
}

KnownVault is one local vault the app knows about.

func KnownVaults

func KnownVaults() []KnownVault

KnownVaults lists every local vault the app knows: its `localVaults` list plus the active `vaultRoot` when it is not listed. Most recently opened first.

type LocalWorkspace

type LocalWorkspace struct {
	Name string `toml:"name"`
	Root string `toml:"root"`
}

LocalWorkspace is a vault directory zn remembers.

type Prefs

type Prefs struct {
	VimMode               bool
	VimInsertEscape       string
	VimYankToClipboard    bool
	WhichKeyHints         bool
	WhichKeyHintMode      string
	WhichKeyHintTimeoutMs int

	SyncTitleHeadingOnRename bool
	EditorTabSize            int
	EditorScrollOff          int
	WordWrap                 bool
	DefaultPaneMode          string
	LineNumberMode           string
	CompletedTaskStyle       string
	TimeFormat               string
	AutoPairs                bool
	MarkdownSnippets         bool
	HideBuiltinTemplates     bool
	TextReplacementsEnabled  bool
	TextReplacements         map[string]string

	// ThemeFamily, ThemeMode and ThemeID are the desktop's theme selection;
	// ThemeTweaks its Quick tweaks (accent and syntax hues, by slug).
	ThemeFamily    string
	ThemeMode      string
	ThemeID        string
	ThemeTweaks    map[string]string
	UnifiedSidebar bool

	NoteSortOrder           string
	GroupByKind             bool
	NestedTags              bool
	QuickNoteDateTitle      bool
	QuickNoteTitlePrefix    string
	CalendarWeekStart       string
	CalendarShowWeekNumbers bool
	TasksViewMode           string
	ShowArchivedTasks       bool
	KanbanGroupBy           string
	KanbanStatuses          []string
	KanbanColumnTitles      map[string]string
	SystemFolderLabels      map[string]string
	WorkflowsEnabled        bool
	AtlasEnabled            bool

	KeymapOverrides map[string]string

	// Terminal-only preferences, from [terminal] in config.toml. The desktop
	// app ignores the table.
	TerminalMouse bool
	PreviewStyle  string
	// TerminalImages is auto, kitty or off: whether the preview paints
	// pictures with the Kitty graphics protocol.
	TerminalImages string
	// TerminalTheme names a theme for zn alone: a family, a theme id or a
	// custom theme. Empty follows the desktop's [appearance] selection.
	TerminalTheme string
}

Prefs is the slice of the portable preferences the CLI and the terminal UI honor. Defaults match the desktop's PORTABLE_DEFAULTS; a missing file or key keeps the default.

func DefaultPrefs

func DefaultPrefs() Prefs

DefaultPrefs are the shipped defaults.

func LoadPrefs

func LoadPrefs() (Prefs, string, error)

LoadPrefs reads config.toml. A missing file is not an error: the defaults come back, with the path the file would live at.

type RemoteProfile

type RemoteProfile struct {
	ID              string
	Name            string
	BaseURL         string
	AuthToken       string
	LastConnectedAt *int64
}

RemoteProfile is a saved ZenNotes server.

func RemoteProfiles

func RemoteProfiles() []RemoteProfile

RemoteProfiles lists every server the app has been connected to, newest first, the legacy single-server `remoteWorkspace` key folded in.

type ServerWorkspace

type ServerWorkspace struct {
	Name string `toml:"name"`
	URL  string `toml:"url"`
}

ServerWorkspace is a ZenNotes server zn remembers; its token is stored separately, keyed by URL.

type Workspaces

type Workspaces struct {
	// Default names the workspace zn uses when no flag or environment
	// variable picks one; empty means follow the desktop app.
	Default string            `toml:"default"`
	Vaults  []LocalWorkspace  `toml:"vault"`
	Servers []ServerWorkspace `toml:"server"`
}

Workspaces is the content of workspaces.toml.

func LoadWorkspaces

func LoadWorkspaces() Workspaces

LoadWorkspaces reads the list; a missing file is an empty list.

func (*Workspaces) AddServer

func (ws *Workspaces) AddServer(name, baseURL string) ServerWorkspace

AddServer remembers a server; the same URL replaces its entry.

func (*Workspaces) AddVault

func (ws *Workspaces) AddVault(name, root string) LocalWorkspace

AddVault remembers a vault directory; the same root replaces its entry.

func (Workspaces) FindServer

func (ws Workspaces) FindServer(selector string) *ServerWorkspace

FindServer matches a saved server by name (case-insensitive) or URL.

func (Workspaces) FindVault

func (ws Workspaces) FindVault(selector string) *LocalWorkspace

FindVault matches a saved vault by name (case-insensitive) or root.

func (Workspaces) Names

func (ws Workspaces) Names() []string

Names lists every saved workspace name, vaults first.

func (*Workspaces) Remove

func (ws *Workspaces) Remove(name string) (string, bool)

Remove forgets a workspace by name; it reports the kind removed.

func (Workspaces) SortedVaults

func (ws Workspaces) SortedVaults() []LocalWorkspace

SortedVaults returns the vaults by name, for stable listings.

func (Workspaces) UniqueName

func (ws Workspaces) UniqueName(base string) string

UniqueName appends 2, 3… to a name until no saved workspace carries it.

Jump to

Keyboard shortcuts

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