config

package
v1.3.7 Latest Latest
Warning

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

Go to latest
Published: May 11, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package config loads, parses, and holds Fern's runtime configuration.

Index

Constants

View Source
const DefaultVaultConfig = `` /* 466-byte string literal not displayed */

DefaultVaultConfig is the template written to a new vault's ".fern/config.toml".

Variables

View Source
var Version = "dev"

Version is the current application version string. Set at build time via ldflags <tag>.

Functions

func ConfigFilePath

func ConfigFilePath() string

ConfigFilePath returns path to ".config/fern/config.toml".

func DetectEditor

func DetectEditor() (string, error)

DetectEditor returns the user's preferred editor from $EDITOR, $VISUAL, $FCEDIT, or a PATH search of common fallback editors.

func EnsureConfigFileExists

func EnsureConfigFileExists(path string) error

EnsureConfigFileExists creates an empty config file if it doesn't exist.

func EnsureShareDirExists

func EnsureShareDirExists() error

EnsureShareDirExists creates the share directory if it doesn't exist.

func ExpandPath

func ExpandPath(path string) string

ExpandPath expands a leading ~/, environment variables, and resolves the result to an absolute path. An empty string is returned unchanged.

func LoadState

func LoadState() fernState

LoadState reads app state from the state file. Returns defaults when the file doesn't exist (fresh install). Paths in the returned struct are expanded.

func SaveState

func SaveState(s fernState) error

SaveState writes app state to the state file.

func ShareDirPath

func ShareDirPath() string

ShareDirPath returns the XDG data directory for fern: ~/.local/share/fern.

func StateFilePath

func StateFilePath() string

StateFilePath returns the path to the fern state file inside the share dir.

func UpdateConfig added in v1.2.0

func UpdateConfig(path string, section string, changes map[string]string) error

UpdateConfig writes changes as "key = value" to the config file at path, scoped to section. A "" section val targets top-level keys (before the first section header). A named section (ex. keybindings.viewer") changes to that block, appending the header if absent.

func UpdateVaultConfig added in v1.2.0

func UpdateVaultConfig(vaultPath string, section string, changes map[string]string) error

UpdateVaultConfig resolves the vault config path, ensures the .fern/ directory exists, then delegates to UpdateConfig.

Types

type Config

type Config struct {
	Vault              string
	Vaults             []string
	Ext                string
	TodayTemplate      bool
	StartJournals      []string
	ShowSidebar        bool
	NotesDir           string
	JournalsDir        string
	TemplatesDir       string
	AssetsDir          string
	AssetDirs          map[string]string // name to expanded absolute path (external dirs)
	BookmarksFile      string
	DailyTemplate      string
	WeeklyTemplate     string
	MonthlyTemplate    string
	YearlyTemplate     string
	FoldLevel          int
	TabSpaces          int
	ExpandTabs         bool // false = Tab inserts \t; true = Tab inserts ShiftWidth spaces
	ShiftWidth         int  // spaces per Tab press when ExpandTabs is true (1-16)
	Theme              string
	StartMode          string
	WeekStart          string // "monday" or "sunday"
	AutoJournalPeriods bool   // auto-open period logs on startup when today is a period boundary
	LinkFormat         string // "wiki" or "markdown"
	NoteFrontmatter    bool   // true = scaffold new notes with title/date/tags frontmatter
	FuzzySearch        bool   // true = append * to bare FTS query terms (prefix matching)
	CheckboxStates     []string
	Keys               Keys
	ViewerKeys         ViewerKeys
	Language           string
	ParseErrors        []string
	// contains filtered or unexported fields
}

Config holds the full runtime configuration for a Fern session.

func Load

func Load() (*Config, error)

Load reads and parses the config file, returning a populated Config.

func LoadConfigs added in v1.2.0

func LoadConfigs(vaultPath, globalConfigPath string) Config

LoadConfigs builds up a full Config for the passed in vault through successive overrides: configDefaults -> global config file -> vault config file. If vaultPath is empty, vault paths and vault overrides are skipped. TOML decode errors are stored & callers must check it.

func (*Config) AddAssetDir added in v1.2.0

func (c *Config) AddAssetDir(name, path string) error

AddAssetDir registers a named external asset directory, validates input, adds it to the in-memory map, and persists state.

func (c *Config) FormatLink(title, path string) string

FormatLink returns a link string in the configured format. title is the display name; path is the vault-relative path without extension.

func (*Config) HasMultipleVaults

func (c *Config) HasMultipleVaults() bool

HasMultipleVaults reports whether more than one vault is configured.

func (*Config) LoadVault added in v0.9.0

func (c *Config) LoadVault(path string) []string

LoadVault switches the active vault to path passed in. It re-composes a fresh Config. If config parse errors are found during loading, return them & abort vault switching (Receiver is left unchanged).

func (*Config) SaveState

func (c *Config) SaveState() error

SaveState persists the active vault, vaults list, asset dirs, and language to the share state file.

func (*Config) UserConfigPath added in v1.2.0

func (c *Config) UserConfigPath() string

UserConfigPath returns the path to the global config file.

type KeybindingsGlobal added in v1.2.0

type KeybindingsGlobal struct {
	Sidebar      string            `toml:"sidebar"`
	CloseTab     string            `toml:"close_tab"`
	NextTab      string            `toml:"next_tab"`
	PrevTab      string            `toml:"prev_tab"`
	MoveTabLeft  string            `toml:"move_tab_left"`
	MoveTabRight string            `toml:"move_tab_right"`
	Palette      string            `toml:"palette"`
	Viewer       KeybindingsViewer `toml:"viewer"`
}

KeybindingsGlobal holds all keybinding overrides from the [keybindings] section. App-level keys are direct fields here (so they live under [keybindings] in TOML). Viewer keys are nested under [keybindings.viewer].

type KeybindingsViewer added in v1.2.0

type KeybindingsViewer struct {
	MoveDown        string `toml:"move_down"`
	MoveUp          string `toml:"move_up"`
	MoveLeft        string `toml:"move_left"`
	MoveRight       string `toml:"move_right"`
	WordForward     string `toml:"word_forward"`
	WordBackward    string `toml:"word_backward"`
	LineStart       string `toml:"line_start"`
	LineEnd         string `toml:"line_end"`
	HalfPageDown    string `toml:"half_page_down"`
	HalfPageUp      string `toml:"half_page_up"`
	GotoPrefix      string `toml:"goto_prefix"`
	GotoEnd         string `toml:"goto_end"`
	Undo            string `toml:"undo"`
	Redo            string `toml:"redo"`
	InsertMode      string `toml:"insert_mode"`
	AppendEnd       string `toml:"append_end"`
	AppendAfter     string `toml:"append_after"`
	InsertAtStart   string `toml:"insert_at_start"`
	ReplaceMode     string `toml:"replace_mode"`
	NewLineBelow    string `toml:"new_line_below"`
	NewLineAbove    string `toml:"new_line_above"`
	ToggleCheckbox  string `toml:"toggle_checkbox"`
	InsertCheckbox  string `toml:"insert_checkbox"`
	VisualMode      string `toml:"visual_mode"`
	VisualLineMode  string `toml:"visual_line_mode"`
	Paste           string `toml:"paste"`
	ReplacePrefix   string `toml:"replace_prefix"`
	DeleteChar      string `toml:"delete_char"`
	DeletePrefix    string `toml:"delete_prefix"`
	Yank            string `toml:"yank"`
	Cut             string `toml:"cut"`
	Change          string `toml:"change"`
	SearchSelection string `toml:"search_selection"`
	FoldExpand      string `toml:"fold_expand"`
	FoldCollapse    string `toml:"fold_collapse"`
	SearchNext      string `toml:"search_next"`
	SearchPrev      string `toml:"search_prev"`
	Escape          string `toml:"escape"`
	Indent          string `toml:"indent"`
	Dedent          string `toml:"dedent"`
}

type Keys

type Keys struct {
	Quit         string
	Search       string
	Command      string
	Help         string
	Edit         string
	Sidebar      string
	CloseTab     string
	NextTab      string
	PrevTab      string
	MoveTabLeft  string
	MoveTabRight string
	Palette      string
}

Keys holds the application-level keybinding strings.

func DefaultKeys

func DefaultKeys() Keys

DefaultKeys returns the built-in default application key bindings.

type NamedAssetDir added in v1.2.0

type NamedAssetDir struct {
	Name string `json:"name"`
	Path string `json:"path"`
}

NamedAssetDir is a device-local directory referenced by alias in asset links.

type VaultConfig added in v0.9.0

type VaultConfig struct {
	Ext                *string
	StartJournals      []string
	AutoJournalPeriods *bool
	WeekStart          *string
	NoteFrontmatter    *bool
	FuzzySearch        *bool
	CheckboxStates     []string
	LinkFormat         *string
	FoldLevel          *int
	TabSpaces          *int
	ExpandTabs         *bool
	ShiftWidth         *int
	Theme              *string
	StartMode          *string
	ShowSidebar        *bool
}

VaultConfig holds the subset of Config fields that can be overridden per-vault via {vault}/.fern/config.toml. Pointer fields allow distinguishing "not set" from "explicitly set to zero value"; nil means no override. Slice fields use nil = not overridden.

type ViewerKeys

type ViewerKeys struct {
	MoveDown        string
	MoveUp          string
	MoveLeft        string
	MoveRight       string
	WordForward     string
	WordBackward    string
	LineStart       string
	LineEnd         string
	HalfPageDown    string
	HalfPageUp      string
	GotoPrefix      string
	GotoEnd         string
	Undo            string
	Redo            string
	InsertMode      string
	AppendEnd       string
	AppendAfter     string
	InsertAtStart   string
	ReplaceMode     string
	NewLineBelow    string
	NewLineAbove    string
	ToggleCheckbox  string
	InsertCheckbox  string
	VisualMode      string
	VisualLineMode  string
	Paste           string
	ReplacePrefix   string
	DeleteChar      string
	DeletePrefix    string
	Yank            string
	Cut             string
	Change          string
	SearchSelection string
	FoldExpand      string
	FoldCollapse    string
	SearchNext      string
	SearchPrev      string
	Escape          string
	Indent          string
	Dedent          string
}

ViewerKeys holds user-configurable keybinding strings for the viewer. Each field is a comma-separated list of key names (e.g. "j,down"). An empty string means "keep the built-in default".

Jump to

Keyboard shortcuts

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