config

package
v1.8.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: AGPL-3.0 Imports: 12 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 config loads, parses, and holds Fern's runtime configuration.

Index

Constants

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

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

Variables

View Source
var DefaultFrontmatterFields = []FrontmatterField{
	{Name: "title", Type: FrontmatterFieldText, Default: "{{TITLE}}"},
	{Name: "tags", Type: FrontmatterFieldTags},
}

DefaultFrontmatterFields is used when NoteFrontmatterFields is nil/empty.

ValidFrontmatterFieldTypes lists all types in cycling order for the modal UI.

View Source
var Version = "dev"

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

Functions

func AddRegistryPlugin added in v1.8.0

func AddRegistryPlugin(name string)

func ApprovePlugin added in v1.8.0

func ApprovePlugin(name string)

func ConfigFilePath

func ConfigFilePath() string

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

func DetectEditor

func DetectEditor() string

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

func EffectiveCheckboxDone added in v1.7.0

func EffectiveCheckboxDone(done string, states []string) string

EffectiveCheckboxDone returns the configured done symbol or the last state.

func EffectiveCheckboxTodo added in v1.7.0

func EffectiveCheckboxTodo(todo string, states []string) string

EffectiveCheckboxTodo returns the configured todo symbol or the first state.

func EnsureConfigFileExists

func EnsureConfigFileExists(path string) error

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

func EnsurePluginsDirExists added in v1.8.0

func EnsurePluginsDirExists()

EnsurePluginsDirExists creates the default plugins directory if it doesn't already exist. Errors are silently ignored; a missing directory is always safe to continue with (plugins are disabled by default anyway).

func EnsureShareDirExists

func EnsureShareDirExists() error

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 GetApprovedPlugins added in v1.8.0

func GetApprovedPlugins() []string

func GetLastSeenVersion added in v1.5.7

func GetLastSeenVersion() string

func GetRegistryPlugins added in v1.8.0

func GetRegistryPlugins() []string

func LoadState

func LoadState() fernState

func RegistryCachePath added in v1.8.0

func RegistryCachePath() string

func RemoveRegistryPlugin added in v1.8.0

func RemoveRegistryPlugin(name string)

func RevokePlugin added in v1.8.0

func RevokePlugin(name string)

func SaveState

func SaveState(s fernState) error

func SetLastSeenVersion added in v1.5.7

func SetLastSeenVersion(version string)

func ShareDirPath

func ShareDirPath() string

func StateFilePath

func StateFilePath() string

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.

func ValidPresets added in v1.5.0

func ValidPresets(p Preset) bool

func ValidateCheckboxRole added in v1.7.0

func ValidateCheckboxRole(name, symbol string, states []string) (string, string)

ValidateCheckboxRole returns symbol unchanged when it is present in states or is empty. Returns "" and a warning string when symbol is non-empty but absent from states. states may be nil (treated as the built-in default pair).

func ValidateFieldDefault added in v1.8.0

func ValidateFieldDefault(typ FrontmatterFieldType, def string) bool

ValidateFieldDefault reports whether def is a legal default for typ. Empty string (no default) is always valid. Values containing "{{" are treated as template tokens and always valid.

Types

type Config

type Config struct {
	Vault                 string
	Vaults                []string
	Ext                   string
	TodayTemplate         bool
	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
	NoteFrontmatterFields []FrontmatterField // nil or empty means to use the DefaultFrontmatterFields
	FuzzySearch           bool               // true = append * to bare FTS query terms (prefix matching)
	SmartIndent           bool               // true = > / < on list items also carries child lines
	SpellCheck            bool               // live spell marking in edit modes; default false
	SpellLang             string             // hunspell dictionary name; default "en_US"
	SuggestLinks          bool               // show link completions in insert mode; default true
	SuggestTags           bool               // show tag completions in insert mode; default true
	CheckboxStates        []string
	CheckboxTodo          string
	CheckboxDone          string
	Keys                  Keys
	ViewerKeys            ViewerKeys
	KeybindingPreset      Preset
	Language              string
	Layout                *LayoutNode
	Plugins               PluginsConfig
	ParseErrors           []string
	ConfigWarnings        []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) PersonalDictPath added in v1.7.0

func (c *Config) PersonalDictPath() string

PersonalDictPath returns the path to the user's personal spell-check dictionary. It is stored alongside the global config file.

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 FrontmatterField added in v1.8.0

type FrontmatterField struct {
	Name    string
	Type    FrontmatterFieldType
	Default string // optional; supports {{TITLE}}, {{DATE}}, {{DATETIME}}
}

FrontmatterField describes a single field in new-note frontmatter scaffolding.

type FrontmatterFieldType added in v1.8.0

type FrontmatterFieldType string

FrontmatterFieldType is the kind of YAML value a frontmatter field holds.

const (
	FrontmatterFieldText     FrontmatterFieldType = "text"
	FrontmatterFieldList     FrontmatterFieldType = "list"
	FrontmatterFieldNumber   FrontmatterFieldType = "number"
	FrontmatterFieldBool     FrontmatterFieldType = "bool"
	FrontmatterFieldDate     FrontmatterFieldType = "date"
	FrontmatterFieldDatetime FrontmatterFieldType = "datetime"
	FrontmatterFieldTags     FrontmatterFieldType = "tags"
)

func NormalizeFrontmatterFieldType added in v1.8.0

func NormalizeFrontmatterFieldType(s string) FrontmatterFieldType

NormalizeFrontmatterFieldType returns the matched constant or FrontmatterFieldText for unrecognized values.

type KeybindingsGlobal added in v1.2.0

type KeybindingsGlobal struct {
	Preset       string            `toml:"preset"`
	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"`
	EnclosePrefix   string `toml:"enclose_prefix"`
	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 LayoutNode added in v1.6.0

type LayoutNode struct {
	Split  string      `toml:"split"` // horizontal | vertical
	Tabs   []LayoutTab `toml:"tabs"`
	Left   *LayoutNode `toml:"left"`   // vert pane
	Right  *LayoutNode `toml:"right"`  // vert pane
	Top    *LayoutNode `toml:"top"`    // horiz pane
	Bottom *LayoutNode `toml:"bottom"` // horiz pane
}

LayoutNode is a node in the startup pane layout tree. Leaf nodes have Tabs; Branch nodes have a Split with two children.

func LoadLayoutFile added in v1.6.0

func LoadLayoutFile(path string) (*LayoutNode, error)

LoadLayoutFile reads a TOML file that contains a [layout] section and returns the normalized LayoutNode or an error.

type LayoutTab added in v1.6.0

type LayoutTab struct {
	File string `toml:"file"`
	Mode string `toml:"mode"`
}

LayoutTab is one tab in a layout leaf node.

type NamedAssetDir added in v1.2.0

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

type PluginsConfig added in v1.8.0

type PluginsConfig struct {
	Enabled bool     // whether to load plugins
	Dir     string   // expanded absolute path to the plugins directory
	Install []string // plugin names declared for installation
}

PluginsConfig holds configuration for the Lua plugin system.

type Preset added in v1.5.0

type Preset string

Preset names a built-in keybinding base layer.

const (
	PresetVim    Preset = "vim"
	PresetEmacs  Preset = "emacs"
	PresetHelix  Preset = "helix"
	PresetArrows Preset = "arrows"
)

func DetectPreset added in v1.5.0

func DetectPreset() Preset

DetectPreset gets a Preset from user's default editor (ie. $EDITOR/$VISUAL/$FCEDIT etc.). Returns PresetArrows when no editor is detected or no direct mapping exists.

type VaultConfig added in v0.9.0

type VaultConfig struct {
	Ext                   *string
	AutoJournalPeriods    *bool
	WeekStart             *string
	NoteFrontmatter       *bool
	NoteFrontmatterFields []FrontmatterField
	FuzzySearch           *bool
	CheckboxStates        []string
	CheckboxTodo          *string
	CheckboxDone          *string
	LinkFormat            *string
	FoldLevel             *int
	TabSpaces             *int
	ExpandTabs            *bool
	ShiftWidth            *int
	Theme                 *string
	StartMode             *string
	ShowSidebar           *bool
	Layout                *LayoutNode
}

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
	EnclosePrefix   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".

func PresetKeys added in v1.5.0

func PresetKeys(p Preset) ViewerKeys

PresetKeys returns the ViewerKeys for a named preset. Defaults to arrows Preset

Jump to

Keyboard shortcuts

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