dotune-0.3.0 is not a library.
dotune
A dotfile manager for configs applied on different operating systems simultaneously. Write Lua scripts to decide where your stuff is being linked to
Example
Say I want to link Vieb configuration:
-- Check if Vieb is installed (if you want)
if not :
-- Use `Path` primitive instead of strings
local src = Path. / 'web/vieb'
Dot.
-- ^ symlink ~/Repos/dotfiles/web/vieb/colors -> ~/.vieb/colors
Dot.
-- ^ symlink ~/Repos/dotfiles/web/vieb/.viebrc -> ~/.viebrc
-- Use `include` to run configs in child folders (like require, but relative)
include -- https://github.com/qutebrowser/qutebrowser
# Execute the script
CLI
# Pass parameters to scripts with -p / --param NAME=VALUE (repeat for multiple pairs)
Porcelain output
Use -o porcelain for easy-to-parse output. Fields are separated by NUL, records by two NUL bytes. The first field defines a kind of record. All paths are absolute and unescaped
| Record | Fields after record name |
|---|---|
dir-created |
directory path |
path-deleted |
deleted path |
symlink-created |
source path, destination path |
symlink-recreated |
source path, destination path |
copied-over |
source path, destination path |
error |
command (link or copy), source path, destination path |
|
Output in stderr is not strict
(Porcelain is meant to be stable, but while we're in v0.x I can't guarantee this)
Lua API
Standard library
Lua scripts have access to very basic parts of standard library: print, string, table and utf8. More complicated stuff like file I/O and environment access are disabled
include
include -- Run shell/.dotune.lua relative to the current script
include -- Nested paths are allowed; absolute paths, . and .. are not
Input
local target = Input. -- Path. May not exist
local profile = Input. -- string. May be empty
Dot.
Dot
Dot.link
-- Create a symlink to a file or directory, creating missing parent directories.
-- Sources must be inside the repository; destinations must be outside it.
-- Replaces existing symlinks; errors if a regular file or directory exists.
Dot.
Dot.copy
-- Copy a file or directory, creating missing parent directories.
-- Sources must be inside the repository; destinations must be outside it.
-- Directories are merged, matching files are overwritten, extra files are kept.
Dot.
Path
local config = Path. / 'config.toml' -- Join; same as Path.here:join('config.toml')
Dot. -- Passes source and destination, keeping the filename
Dot. -- Choose a different destination name
local renamed = config % 'app.toml' -- Replace filename; :with_tail('app.toml')
local backup = config * 'bak' -- Replace extension; :with_extension('bak')
local parent = config. -- Parent path, or nil at the filesystem root
local exists = config: -- Whether the path exists
local resolved = config: -- Absolute path with symlinks resolved, or nil on failure
local text = tostring -- Convert a Path to a string
local binary = Path. -- Find an executable on PATH, or return nil
local home = Path. -- User's home directory
local here = Path. -- Current script's directory; alias of Path.script_dir
local script = Path. -- Current .dotune.lua file
local root = Path. -- Filesystem root (e.g. / or C:\)
XDG
-- Uses XDG environment variables, falling back to these paths under Path.home:
local config = XDG. -- XDG_CONFIG_HOME: ~/.config
local data = XDG. -- XDG_DATA_HOME: ~/.local/share
local state = XDG. -- XDG_STATE_HOME: ~/.local/state
local cache = XDG. -- XDG_CACHE_HOME: ~/.cache
OS
local config = OS.
-- Priority: exact OS, then unix, then _;
-- All keys are optional, but no match is an error
local is_windows = OS.
-- ^ Same thing just for boolean conditions
Platform paths
(Not all paths are defined yet, more like a proof of concept for now)
Windows
local roaming = Windows. -- APPDATA, or ~/AppData/Roaming
local local_data = Windows. -- LOCALAPPDATA, or ~/AppData/Local
local low = Windows. -- ~/AppData/LocalLow
local documents = Windows. -- ~/Documents
Mac
local applications = Mac. -- /Applications
Development