Standardize documentation for extended config
[dotbot.git] / README.md
blobae7e5701c749e72c688987aced93e65ba3583b75
1 # Dotbot [![Build Status](https://travis-ci.com/anishathalye/dotbot.svg?branch=master)](https://travis-ci.com/anishathalye/dotbot)
3 Dotbot makes installing your dotfiles as easy as `git clone $url && cd dotfiles
4 && ./install`, even on a freshly installed system!
6 - [Rationale](#rationale)
7 - [Getting Started](#getting-started)
8 - [Configuration](#configuration)
9 - [Directives](#directives) ([Link](#link), [Create](#create), [Shell](#shell), [Clean](#clean), [Defaults](#defaults))
10 - [Plugins](#plugins)
11 - [Command-line Arguments](#command-line-arguments)
12 - [Wiki][wiki]
14 ---
16 ## Rationale
18 Dotbot is a tool that bootstraps your dotfiles (it's a [Dot]files
19 [bo]o[t]strapper, get it?). It does *less* than you think, because version
20 control systems do more than you think.
22 Dotbot is designed to be lightweight and self-contained, with no external
23 dependencies and no installation required. Dotbot can also be a drop-in
24 replacement for any other tool you were using to manage your dotfiles, and
25 Dotbot is VCS-agnostic -- it doesn't make any attempt to manage your dotfiles.
27 If you want an in-depth tutorial about organizing your dotfiles, see this [blog
28 post][managing-dotfiles-post].
30 ## Getting Started
32 ### Starting Fresh?
34 Great! You can automate the creation of your dotfiles by using the
35 user-contributed [init-dotfiles][init-dotfiles] script. If you'd rather use a
36 template repository, check out [dotfiles_template][dotfiles-template]. Or, if
37 you're just looking for [some inspiration][inspiration], we've got you covered.
39 ### Integrate with Existing Dotfiles
41 The following will help you get set up using Dotbot in just a few steps.
43 If you're using **Git**, you can add Dotbot as a submodule:
45 ```bash
46 cd ~/.dotfiles # replace with the path to your dotfiles
47 git init # initialize repository if needed
48 git submodule add https://github.com/anishathalye/dotbot
49 git config -f .gitmodules submodule.dotbot.ignore dirty # ignore dirty commits in the submodule
50 cp dotbot/tools/git-submodule/install .
51 touch install.conf.yaml
52 ```
54 If you're using **Mercurial**, you can add Dotbot as a subrepo:
56 ```bash
57 cd ~/.dotfiles # replace with the path to your dotfiles
58 hg init # initialize repository if needed
59 echo "dotbot = [git]https://github.com/anishathalye/dotbot" > .hgsub
60 hg add .hgsub
61 git clone https://github.com/anishathalye/dotbot
62 cp dotbot/tools/hg-subrepo/install .
63 touch install.conf.yaml
64 ```
66 To get started, you just need to fill in the `install.conf.yaml` and Dotbot
67 will take care of the rest. To help you get started we have [an
68 example](#full-example) config file as well as [configuration
69 documentation](#configuration) for the accepted parameters.
71 Note: The `install` script is merely a shim that checks out the appropriate
72 version of Dotbot and calls the full Dotbot installer. By default, the script
73 assumes that the configuration is located in `install.conf.yaml` the Dotbot
74 submodule is located in `dotbot`. You can change either of these parameters by
75 editing the variables in the `install` script appropriately.
77 Setting up Dotbot as a submodule or subrepo locks it on the current version.
78 You can upgrade Dotbot at any point. If using a submodule, run `git submodule
79 update --remote dotbot`, substituting `dotbot` with the path to the Dotbot
80 submodule; be sure to commit your changes before running `./install`, otherwise
81 the old version of Dotbot will be checked out by the install script. If using a
82 subrepo, run `git fetch && git checkout origin/master` in the Dotbot directory.
84 If you prefer, you can install Dotbot from [PyPI] and call it as a command-line
85 program:
87 ```bash
88 pip install dotbot
89 touch install.conf.yaml
90 ```
92 In this case, rather than running `./install`, you can invoke Dotbot with
93 `dotbot -c <path to configuration file>`.
95 ### Full Example
97 Here's an example of a complete configuration.
99 The conventional name for the configuration file is `install.conf.yaml`.
101 ```yaml
102 - defaults:
103     link:
104       relink: true
106 - clean: ['~']
108 - link:
109     ~/.tmux.conf: tmux.conf
110     ~/.vim: vim
111     ~/.vimrc: vimrc
113 - create:
114     - ~/downloads
115     - ~/.vim/undo-history
117 - shell:
118   - [git submodule update --init --recursive, Installing submodules]
121 The configuration file is typically written in YAML, but it can also be written
122 in JSON (which is a [subset of YAML][json2yaml]). JSON configuration files are
123 conventionally named `install.conf.json`.
125 ## Configuration
127 Dotbot uses YAML or JSON-formatted configuration files to let you specify how
128 to set up your dotfiles. Currently, Dotbot knows how to [link](#link) files and
129 folders, [create](#create) folders, execute [shell](#shell) commands, and
130 [clean](#clean) directories of broken symbolic links. Dotbot also supports user
131 [plugins](#plugins) for custom commands.
133 **Ideally, bootstrap configurations should be idempotent. That is, the
134 installer should be able to be run multiple times without causing any
135 problems.** This makes a lot of things easier to do (in particular, syncing
136 updates between machines becomes really easy).
138 Dotbot configuration files are arrays of tasks, where each task
139 is a dictionary that contains a command name mapping to data for that command.
140 Tasks are run in the order in which they are specified. Commands within a task
141 do not have a defined ordering.
143 When writing nested constructs, keep in mind that YAML is whitespace-sensitive.
144 Following the formatting used in the examples is a good idea. If a YAML
145 configuration file is not behaving as you expect, try inspecting the
146 [equivalent JSON][json2yaml] and check that it is correct.
148 ## Directives
150 Most Dotbot commands support both a simplified and extended syntax, and they
151 can also be configured via setting [defaults](#defaults).
153 ### Link
155 Link commands specify how files and directories should be symbolically linked.
156 If desired, items can be specified to be forcibly linked, overwriting existing
157 files if necessary. Environment variables in paths are automatically expanded.
159 #### Format
161 Link commands are specified as a dictionary mapping targets to source
162 locations. Source locations are specified relative to the base directory (that
163 is specified when running the installer). If linking directories, *do not*
164 include a trailing slash.
166 Link commands support an optional extended configuration. In this type of
167 configuration, instead of specifying source locations directly, targets are
168 mapped to extended configuration dictionaries.
170 | Parameter | Explanation |
171 | --- | --- |
172 | `path` | The source for the symlink, the same as in the shortcut syntax (default: null, automatic (see below)) |
173 | `create` | When true, create parent directories to the link as needed. (default: false) |
174 | `relink` | Removes the old target if it's a symlink (default: false) |
175 | `force` | Force removes the old target, file or folder, and forces a new link (default: false) |
176 | `relative` | Use a relative path to the source when creating the symlink (default: false, absolute links) |
177 | `canonicalize-path` | Resolve any symbolic links encountered in the source to symlink to the canonical path (default: true, real paths) |
178 | `glob` | Treat a `*` character as a wildcard, and perform link operations on all of those matches (default: false) |
179 | `if` | Execute this in your `$SHELL` and only link if it is successful. |
180 | `ignore-missing` | Do not fail if the source is missing and create the link anyway (default: false) |
182 #### Example
184 ```yaml
185 - link:
186     ~/.config/terminator:
187       create: true
188       path: config/terminator
189     ~/.vim: vim
190     ~/.vimrc:
191       relink: true
192       path: vimrc
193     ~/.zshrc:
194       force: true
195       path: zshrc
196     ~/.hammerspoon:
197       if: '[ `uname` = Darwin ]'
198       path: hammerspoon
201 If the source location is omitted or set to `null`, Dotbot will use the
202 basename of the destination, with a leading `.` stripped if present. This makes
203 the following two config files equivalent.
205 Explicit sources:
207 ```yaml
208 - link:
209     ~/bin/ack: ack
210     ~/.vim: vim
211     ~/.vimrc:
212       relink: true
213       path: vimrc
214     ~/.zshrc:
215       force: true
216       path: zshrc
217     ~/.config/:
218       glob: true
219       path: config/*
220       relink: true
223 Implicit sources:
225 ```yaml
226 - link:
227     ~/bin/ack:
228     ~/.vim:
229     ~/.vimrc:
230       relink: true
231     ~/.zshrc:
232       force: true
233     ~/.config/:
234       glob: true
235       path: config/*
236       relink: true
239 ### Create
241 Create commands specify empty directories to be created.  This can be useful
242 for scaffolding out folders or parent folder structure required for various
243 apps, plugins, shell commands, etc.
245 #### Format
247 Create commands are specified as an array of directories to be created.
249 #### Example
251 ```yaml
252 - create:
253     - ~/projects
254     - ~/downloads
255     - ~/.vim/undo-history
258 ### Shell
260 Shell commands specify shell commands to be run. Shell commands are run in the
261 base directory (that is specified when running the installer).
263 #### Format
265 Shell commands can be specified in several different ways. The simplest way is
266 just to specify a command as a string containing the command to be run.
268 Another way is to specify a two element array where the first element is the
269 shell command and the second is an optional human-readable description.
271 Shell commands support an extended syntax as well, which provides more
272 fine-grained control.
274 | Parameter | Explanation |
275 | --- | --- |
276 | `command` | The command to be run |
277 | `description` | A human-readable message describing the command (default: null) |
278 | `quiet` | Show only the description but not the command in log output (default: false) |
279 | `stdin` | Allow a command to read from standard input (default: false) |
280 | `stdout` | Show a command's output from stdout (default: false) |
281 | `stderr` | Show a command's error output from stderr (default: false) |
283 Note that `quiet` controls whether the command (a string) is printed in log
284 output, it does not control whether the output from running the command is
285 printed (that is controlled by `stdout` / `stderr`). When a command's `stdin` /
286 `stdout` / `stderr` is not enabled (which is the default), it's connected to
287 `/dev/null`, disabling input and hiding output.
289 #### Example
291 ```yaml
292 - shell:
293   - chsh -s $(which zsh)
294   - [chsh -s $(which zsh), Making zsh the default shell]
295   -
296     command: read var && echo Your variable is $var
297     stdin: true
298     stdout: true
299     description: Reading and printing variable
300     quiet: true
301   -
302     command: read fail
303     stderr: true
306 ### Clean
308 Clean commands specify directories that should be checked for dead symbolic
309 links. These dead links are removed automatically. Only dead links that point
310 to somewhere within the dotfiles directory are removed unless the `force`
311 option is set to `true`.
313 #### Format
315 Clean commands are specified as an array of directories to be cleaned.
317 Clean commands also support an extended configuration syntax.
319 | Parameter | Explanation |
320 | --- | --- |
321 | `force` | Remove dead links even if they don't point to a file inside the dotfiles directory (default: false) |
322 | `recursive` | Traverse the directory recursively looking for dead links (default: false) |
324 Note: using the `recursive` option for `~` is not recommended because it will
325 be slow.
327 #### Example
329 ```yaml
330 - clean: ['~']
332 - clean:
333     ~/:
334       force: true
335     ~/.config:
336       recursive: true
339 ### Defaults
341 Default options for plugins can be specified so that options don't have to be
342 repeated many times. This can be very useful to use with the link command, for
343 example.
345 Defaults apply to all commands that come after setting the defaults. Defaults
346 can be set multiple times; each change replaces the defaults with a new set of
347 options.
349 #### Format
351 Defaults are specified as a dictionary mapping action names to settings, which
352 are dictionaries from option names to values.
354 #### Example
356 ```yaml
357 - defaults:
358     link:
359       create: true
360       relink: true
363 ### Plugins
365 Dotbot also supports custom directives implemented by plugins. Plugins are
366 implemented as subclasses of `dotbot.Plugin`, so they must implement
367 `can_handle()` and `handle()`. The `can_handle()` method should return `True`
368 if the plugin can handle an action with the given name. The `handle()` method
369 should do something and return whether or not it completed successfully.
371 All built-in Dotbot directives are written as plugins that are loaded by
372 default, so those can be used as a reference when writing custom plugins.
374 Plugins are loaded using the `--plugin` and `--plugin-dir` options, using
375 either absolute paths or paths relative to the base directory. It is
376 recommended that these options are added directly to the `install` script.
378 See [here][plugins] for a current list of plugins.
380 ## Command-line Arguments
382 Dotbot takes a number of command-line arguments; you can run Dotbot with
383 `--help`, e.g. by running `./install --help`, to see the full list of options.
384 Here, we highlight a couple that are particularly interesting.
386 ### `--only`
388 You can call `./install --only [list of directives]`, such as `./install --only
389 link`, and Dotbot will only run those sections of the config file.
391 ### `--except`
393 You can call `./install --except [list of directives]`, such as `./install
394 --except shell`, and Dotbot will run all the sections of the config file except
395 the ones listed.
397 ## Wiki
399 Check out the [Dotbot wiki][wiki] for more information, tips and tricks,
400 user-contributed plugins, and more.
402 ## Contributing
404 Do you have a feature request, bug report, or patch? Great! See
405 [CONTRIBUTING.md][contributing] for information on what you can do about that.
407 ## Packaging
409 1. Update version information.
411 2. Build the package using ``python setup.py sdist bdist_wheel``.
413 3. Sign and upload the package using ``twine upload -s dist/*``.
415 ## License
417 Copyright (c) 2014-2020 Anish Athalye. Released under the MIT License. See
418 [LICENSE.md][license] for details.
420 [PyPI]: https://pypi.org/project/dotbot/
421 [init-dotfiles]: https://github.com/Vaelatern/init-dotfiles
422 [dotfiles-template]: https://github.com/anishathalye/dotfiles_template
423 [inspiration]: https://github.com/anishathalye/dotbot/wiki/Users
424 [managing-dotfiles-post]: http://www.anishathalye.com/2014/08/03/managing-your-dotfiles/
425 [json2yaml]: https://www.json2yaml.com/
426 [plugins]: https://github.com/anishathalye/dotbot/wiki/Plugins
427 [wiki]: https://github.com/anishathalye/dotbot/wiki
428 [contributing]: CONTRIBUTING.md
429 [license]: LICENSE.md