Documentation ¶
Overview ¶
Package config loads, validates, and applies tmpl configurations.
Index ¶
Constants ¶
const DefaultConfigFile = ".tmpl.yaml"
DefaultConfigFile is the default configuration filename.
Variables ¶
var ( // ErrConfigNotFound is returned when a configuration file is not found. ErrConfigNotFound = errors.New("configuration file not found") // ErrEmptyConfig is returned when a configuration file is empty. ErrEmptyConfig = errors.New("configuration file is empty") // ErrInvalidConfig is returned when a configuration file contains invalid // and unparsable YAML. ErrInvalidConfig = errors.New("configuration file is not parsable") )
Functions ¶
func Apply ¶
Apply applies the provided tmux session configuration using the provided tmux command.
If a session with the same name already exists, it is assumed to be in the correct state and the session is returned. Otherwise, a new session is created and returned.
If the provided configuration is invalid, an error is returned. Caller can check for validity beforehand by calling config.Config.Validate if needed.
func ConfigFileName ¶
func ConfigFileName() string
ConfigFileName returns the name of the configuration that.
Returns the value of the TMPL_CONFIG_NAME environment variable if set, otherwise it returns DefaultConfigFile.
func FindConfigFile ¶
FindConfigFile searches for a configuration file starting from the provided directory and going up until the root directory is reached. If no file is found, ErrConfigNotFound is returned.
By default, the configuration file name is .tmpl.yaml. This can be changed by setting the TMPL_CONFIG_FILE environment variable.
Types ¶
type Config ¶
type Config struct { Session SessionConfig `yaml:"session"` // Session configuration. Tmux string `yaml:"tmux"` // Path to tmux executable. TmuxOptions []string `yaml:"tmux_options"` // Additional tmux options. // contains filtered or unexported fields }
Config represents a session configuration loaded from a YAML file.
func FromFile ¶
FromFile loads a session configuration from provided file path.
File is expected to be in YAML format.
func (*Config) NumWindows ¶
NumWindows returns the number of window configurations for the session.
func (*Config) Path ¶
Path returns the path to the configuration file from which the configuration was loaded.
func (Config) Validate ¶
Validate validates the configuration.
It checks that:
- tmux executable exists
- session is valid (see SessionConfig.Validate)
If any of the above checks fail, an error is returned.
type DecodeError ¶
type DecodeError struct {
// contains filtered or unexported fields
}
DecodeError is returned when a configuration file cannot be decoded.
func (DecodeError) Error ¶
func (e DecodeError) Error() string
Error implements the error interface.
func (DecodeError) Path ¶
func (e DecodeError) Path() string
Path returns the path to the configuration file that was attempted to be decoded.
func (DecodeError) Unwrap ¶
func (e DecodeError) Unwrap() error
Unwrap implements the errors.Wrapper interface.
type PaneConfig ¶
type PaneConfig struct { Env map[string]string `yaml:"env"` // Pane environment variables. Path string `yaml:"path"` // Pane directory. Command string `yaml:"command"` // Command to run in the pane. Commands []string `yaml:"commands"` // Commands to run in the pane. Size string `yaml:"size"` // Pane size (cells or percentage) Horizontal bool `yaml:"horizontal"` // Whether the pane should be split horizontally. Panes []PaneConfig `yaml:"panes"` // Pane configurations. Active bool `yaml:"active"` // Whether the pane should be selected. }
PaneConfig represents a tmux pane configuration. It contains the path to the directory where the pane will be created, the command to run in the pane, the size of the pane and whether the pane should be split horizontally or vertically.
If a path is not specified, a pane will inherit the window path.
Any inherited environment variables from the window or session will be overridden by variables defined in the pane configuration if they have the same name.
func (PaneConfig) Validate ¶
func (p PaneConfig) Validate() error
Validate validates the pane configuration.
It checks that:
- pane path exists
- pane environment variable names are valid
- panes are valid
If any of the above checks fail, an error is returned.
type SessionConfig ¶
type SessionConfig struct { Name string `yaml:"name"` // Session name. Path string `yaml:"path"` // Session directory. OnWindow string `yaml:"on_window"` // Shell command to run in all windows. OnPane string `yaml:"on_pane"` // Shell command to run in all panes. OnAny string `yaml:"on_any"` // Shell command to run in all windows and panes. Env map[string]string `yaml:"env"` // Session environment variables. Windows []WindowConfig `yaml:"windows"` // Window configurations. }
SessionConfig represents a tmux session configuration. It contains the name of the session, the path to the directory where the session will be created and the window configurations.
Any environment variables defined in the session configuration will be inherited by all windows and panes.
func (SessionConfig) Validate ¶
func (s SessionConfig) Validate() error
Validate validates the session configuration.
It checks that:
- session name only contains alphanumeric characters, underscores, dots, and dashes
- session path exists
- session environment variable names are valid
- windows are valid (see WindowConfig.Validate)
If any of the above checks fail, an error is returned.
type WindowConfig ¶
type WindowConfig struct { Name string `yaml:"name"` // Window name. Path string `yaml:"path"` // Window directory. Command string `yaml:"command"` // Command to run in the window. Commands []string `yaml:"commands"` // Commands to run in the window. Env map[string]string `yaml:"env"` // Window environment variables. Panes []PaneConfig `yaml:"panes"` // Pane configurations. Active bool `yaml:"active"` // Whether the window should be selected. }
WindowConfig represents a tmux window configuration. It contains the name of the window, the path to the directory where the window will be created, the command to run in the window and pane configurations.
If a path is not specified, a window will inherit the session path.
Any environment variables defined in the window configuration will be inherited by all panes. If a variable is defined in both the session and window configuration, the window variable will take precedence.
func (WindowConfig) Validate ¶
func (w WindowConfig) Validate() error
Validate validates the window configuration.
It checks that:
- window name only contains alphanumeric characters, underscores, dots, and dashes
- window path exists
- window environment variable names are valid
- panes are valid (see PaneConfig.Validate)
If any of the above checks fail, an error is returned.