2023-09-09 21:03:11 -04:00
# Dotbot [![Build Status](https://github.com/anishathalye/dotbot/workflows/CI/badge.svg)](https://github.com/anishathalye/dotbot/actions?query=workflow%3ACI) [![Coverage](https://codecov.io/gh/anishathalye/dotbot/branch/master/graph/badge.svg)](https://app.codecov.io/gh/anishathalye/dotbot) [![PyPI](https://img.shields.io/pypi/v/dotbot.svg)](https://pypi.org/pypi/dotbot/) [![Python 3.6+](https://img.shields.io/badge/python-3.6%2B-blue)](https://pypi.org/pypi/dotbot/)
2014-03-20 22:33:37 -04:00
2016-01-11 13:56:56 -05:00
Dotbot makes installing your dotfiles as easy as `git clone $url & & cd dotfiles
& & ./install`, even on a freshly installed system!
2019-10-24 20:39:07 -04:00
- [Rationale ](#rationale )
- [Getting Started ](#getting-started )
- [Configuration ](#configuration )
2019-11-12 15:01:03 -05:00
- [Directives ](#directives ) ([Link](#link), [Create ](#create ), [Shell ](#shell ), [Clean ](#clean ), [Defaults ](#defaults ))
- [Plugins ](#plugins )
2020-03-25 21:38:39 -04:00
- [Command-line Arguments ](#command-line-arguments )
2019-10-24 20:39:07 -04:00
- [Wiki][wiki]
2016-01-11 13:56:56 -05:00
---
2019-10-24 20:39:07 -04:00
## Rationale
2016-01-16 00:01:40 -05:00
2014-03-20 22:33:37 -04:00
Dotbot is a tool that bootstraps your dotfiles (it's a [Dot]files
[bo]o[t]strapper, get it?). It does *less* than you think, because version
control systems do more than you think.
Dotbot is designed to be lightweight and self-contained, with no external
2015-04-26 19:52:24 -04:00
dependencies and no installation required. Dotbot can also be a drop-in
replacement for any other tool you were using to manage your dotfiles, and
Dotbot is VCS-agnostic -- it doesn't make any attempt to manage your dotfiles.
2014-03-20 22:33:37 -04:00
2020-12-23 18:26:56 -05:00
See [this blog
post](https://www.anishathalye.com/2014/08/03/managing-your-dotfiles/) or more
resources on the [tutorials
page](https://github.com/anishathalye/dotbot/wiki/Tutorials) for more detailed
explanations of how to organize your dotfiles.
2014-03-20 22:33:37 -04:00
2019-10-24 20:39:07 -04:00
## Getting Started
2014-03-20 22:33:37 -04:00
2015-04-26 19:52:24 -04:00
### Starting Fresh?
2014-03-20 22:33:37 -04:00
2015-06-12 00:38:52 -04:00
Great! You can automate the creation of your dotfiles by using the
user-contributed [init-dotfiles][init-dotfiles] script. If you'd rather use a
template repository, check out [dotfiles_template][dotfiles-template]. Or, if
you're just looking for [some inspiration][inspiration], we've got you covered.
2014-03-20 22:33:37 -04:00
2015-04-26 19:52:24 -04:00
### Integrate with Existing Dotfiles
2014-03-20 22:33:37 -04:00
2015-04-26 19:52:24 -04:00
The following will help you get set up using Dotbot in just a few steps.
2014-03-20 22:33:37 -04:00
2019-02-06 09:30:49 -05:00
If you're using **Git** , you can add Dotbot as a submodule:
2015-05-22 13:33:10 -04:00
```bash
2015-10-19 10:13:23 -04:00
cd ~/.dotfiles # replace with the path to your dotfiles
2016-08-15 20:44:30 -04:00
git init # initialize repository if needed
2015-05-22 13:33:10 -04:00
git submodule add https://github.com/anishathalye/dotbot
2019-09-16 15:50:37 -04:00
git config -f .gitmodules submodule.dotbot.ignore dirty # ignore dirty commits in the submodule
2015-05-22 13:33:10 -04:00
cp dotbot/tools/git-submodule/install .
touch install.conf.yaml
```
2019-02-06 09:30:49 -05:00
If you're using **Mercurial** , you can add Dotbot as a subrepo:
2015-05-22 13:33:10 -04:00
2015-04-26 19:52:24 -04:00
```bash
2015-10-19 10:13:23 -04:00
cd ~/.dotfiles # replace with the path to your dotfiles
2016-08-15 20:44:30 -04:00
hg init # initialize repository if needed
2015-05-22 13:33:10 -04:00
echo "dotbot = [git]https://github.com/anishathalye/dotbot" > .hgsub
hg add .hgsub
git clone https://github.com/anishathalye/dotbot
cp dotbot/tools/hg-subrepo/install .
touch install.conf.yaml
2015-04-26 19:52:24 -04:00
```
2014-03-20 22:33:37 -04:00
2020-11-21 20:28:21 -05:00
If you are using PowerShell instead of a POSIX shell, you can use the provided
2022-12-17 15:12:43 -05:00
`install.ps1` script instead of `install` . On Windows, Dotbot only supports
Python 3.8+, and it requires that your account is [allowed to create symbolic
links][windows-symlinks].
2020-11-21 20:28:21 -05:00
2015-05-22 13:33:10 -04:00
To get started, you just need to fill in the `install.conf.yaml` and Dotbot
will take care of the rest. To help you get started we have [an
2015-04-26 19:52:24 -04:00
example](#full-example) config file as well as [configuration
documentation](#configuration) for the accepted parameters.
2014-03-20 22:33:37 -04:00
2015-04-26 19:52:24 -04:00
Note: The `install` script is merely a shim that checks out the appropriate
version of Dotbot and calls the full Dotbot installer. By default, the script
assumes that the configuration is located in `install.conf.yaml` the Dotbot
submodule is located in `dotbot` . You can change either of these parameters by
2015-06-07 11:31:34 -04:00
editing the variables in the `install` script appropriately.
2014-03-20 22:33:37 -04:00
2015-06-03 01:46:39 -04:00
Setting up Dotbot as a submodule or subrepo locks it on the current version.
You can upgrade Dotbot at any point. If using a submodule, run `git submodule
update --remote dotbot`, substituting `dotbot` with the path to the Dotbot
2017-04-19 08:46:45 -04:00
submodule; be sure to commit your changes before running `./install` , otherwise
the old version of Dotbot will be checked out by the install script. If using a
subrepo, run `git fetch && git checkout origin/master` in the Dotbot directory.
2014-10-22 11:10:49 -04:00
2018-05-30 09:41:55 -04:00
If you prefer, you can install Dotbot from [PyPI] and call it as a command-line
program:
```bash
pip install dotbot
touch install.conf.yaml
```
In this case, rather than running `./install` , you can invoke Dotbot with
`dotbot -c <path to configuration file>` .
2015-04-26 19:52:24 -04:00
### Full Example
Here's an example of a complete configuration.
The conventional name for the configuration file is `install.conf.yaml` .
```yaml
2016-03-02 20:53:19 -05:00
- defaults:
link:
relink: true
2015-04-26 19:52:24 -04:00
- clean: ['~']
- link:
~/.tmux.conf: tmux.conf
2016-02-14 22:39:48 -05:00
~/.vim: vim
2015-04-26 19:52:24 -04:00
~/.vimrc: vimrc
2019-10-06 01:13:51 -04:00
- create:
- ~/downloads
- ~/.vim/undo-history
2015-04-26 19:52:24 -04:00
- shell:
- [git submodule update --init --recursive, Installing submodules]
2014-10-22 11:10:49 -04:00
```
2014-03-20 22:33:37 -04:00
2019-02-06 09:30:49 -05:00
The configuration file is typically written in YAML, but it can also be written
2020-06-19 20:28:47 -04:00
in JSON (which is a [subset of YAML][json2yaml]). JSON configuration files are
conventionally named `install.conf.json` .
2015-02-12 21:56:38 -05:00
2019-10-24 20:39:07 -04:00
## Configuration
2015-04-26 19:52:24 -04:00
2019-02-06 09:30:49 -05:00
Dotbot uses YAML or JSON-formatted configuration files to let you specify how
2016-01-13 11:29:12 -05:00
to set up your dotfiles. Currently, Dotbot knows how to [link ](#link ) files and
2019-10-06 01:13:51 -04:00
folders, [create ](#create ) folders, execute [shell ](#shell ) commands, and
[clean ](#clean ) directories of broken symbolic links. Dotbot also supports user
[plugins ](#plugins ) for custom commands.
2014-03-20 22:33:37 -04:00
**Ideally, bootstrap configurations should be idempotent. That is, the
installer should be able to be run multiple times without causing any
2014-10-22 11:10:49 -04:00
problems.** This makes a lot of things easier to do (in particular, syncing
updates between machines becomes really easy).
2014-03-20 22:33:37 -04:00
2015-04-26 19:52:24 -04:00
Dotbot configuration files are arrays of tasks, where each task
2014-10-27 20:04:00 -04:00
is a dictionary that contains a command name mapping to data for that command.
Tasks are run in the order in which they are specified. Commands within a task
do not have a defined ordering.
2014-10-22 11:10:49 -04:00
2015-03-26 22:41:49 -04:00
When writing nested constructs, keep in mind that YAML is whitespace-sensitive.
2019-02-06 09:30:49 -05:00
Following the formatting used in the examples is a good idea. If a YAML
configuration file is not behaving as you expect, try inspecting the
[equivalent JSON][json2yaml] and check that it is correct.
2015-03-26 22:41:49 -04:00
2019-10-24 20:39:07 -04:00
## Directives
2020-06-19 20:28:47 -04:00
Most Dotbot commands support both a simplified and extended syntax, and they
can also be configured via setting [defaults ](#defaults ).
2014-10-22 11:10:49 -04:00
### Link
Link commands specify how files and directories should be symbolically linked.
2014-10-22 13:27:34 -04:00
If desired, items can be specified to be forcibly linked, overwriting existing
2015-05-12 20:04:42 -04:00
files if necessary. Environment variables in paths are automatically expanded.
2014-10-22 11:10:49 -04:00
#### Format
Link commands are specified as a dictionary mapping targets to source
locations. Source locations are specified relative to the base directory (that
2020-06-19 20:28:47 -04:00
is specified when running the installer). If linking directories, *do not*
include a trailing slash.
2014-10-22 11:10:49 -04:00
2020-06-19 20:28:47 -04:00
Link commands support an optional extended configuration. In this type of
2014-10-22 13:27:34 -04:00
configuration, instead of specifying source locations directly, targets are
2018-01-31 18:32:00 -05:00
mapped to extended configuration dictionaries.
2023-09-27 15:31:47 -04:00
| Parameter | Explanation |
|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
| `path` | The source for the symlink, the same as in the shortcut syntax (default: null, automatic (see below)) |
| `create` | When true, create parent directories to the link as needed. (default: false) |
| `relink` | Removes the old target if it's a symlink (default: false) |
| `force` | Force removes the old target, file or folder, and forces a new link (default: false) |
| `backup` | Backup existing files/directories if they exist, creating a backup with suffix `.dotbot-backup (default: false) |
| `relative` | Use a relative path to the source when creating the symlink (default: false, absolute links) |
| `canonicalize` | Resolve any symbolic links encountered in the source to symlink to the canonical path (default: true, real paths) |
| `if` | Execute this in your `$SHELL` and only link if it is successful. |
| `ignore-missing` | Do not fail if the source is missing and create the link anyway (default: false) |
| `glob` | Treat `path` as a glob pattern, expanding patterns referenced below, linking all *files* matched. (default: false) |
| `exclude` | Array of glob patterns to remove from glob matches. Uses same syntax as `path` . Ignored if `glob` is `false` . (default: empty, keep all matches) |
| `prefix` | Prepend prefix prefix to basename of each file when linked, when `glob` is `true` . (default: '') |
2014-10-22 13:27:34 -04:00
2021-05-27 12:58:55 -04:00
When `glob: True` , Dotbot uses [glob.glob ](https://docs.python.org/3/library/glob.html#glob.glob ) to resolve glob paths, expanding Unix shell-style wildcards, which are **not** the same as regular expressions; Only the following are expanded:
2023-09-09 20:39:45 -04:00
| Pattern | Meaning |
|:---------|:-----------------------------------|
| `*` | matches anything |
| `**` | matches any **file** , recursively |
| `?` | matches any single character |
| `[seq]` | matches any character in `seq` |
| `[!seq]` | matches any character not in `seq` |
2021-05-27 12:58:55 -04:00
2021-10-25 14:19:41 -04:00
However, due to the design of `glob.glob` , using a glob pattern such as `config/*` , will **not** match items that begin with `.` . To specifically capture items that being with `.` , you will need to include the `.` in the pattern, like this: `config/.*` .
2020-11-21 10:00:37 -05:00
2023-07-09 15:37:42 -04:00
When using glob with the `exclude:` option, the paths in the exclude paths should be relative to the base directory, same as the glob pattern itself. For example, if a glob pattern `vim/*` matches directories `vim/autoload` , `vim/ftdetect` , `vim/ftplugin` , and `vim/spell` , and you want to ignore the spell directory, then you should use `exclude: ["vim/spell"]` (not just `"spell"` ).
2015-02-10 18:33:37 -05:00
#### Example
2014-10-27 20:04:00 -04:00
```yaml
- link:
~/.config/terminator:
create: true
2016-02-14 22:39:48 -05:00
path: config/terminator
~/.vim: vim
2015-05-02 22:27:05 -04:00
~/.vimrc:
relink: true
path: vimrc
2014-10-27 20:04:00 -04:00
~/.zshrc:
force: true
path: zshrc
2019-11-14 16:30:47 -05:00
~/.hammerspoon:
if: '[ `uname` = Darwin ]'
path: hammerspoon
2021-05-27 12:58:55 -04:00
~/.config/:
path: dotconf/config/**
2021-05-27 13:07:17 -04:00
~/:
glob: true
path: dotconf/*
prefix: '.'
2014-10-27 20:04:00 -04:00
```
2016-11-18 18:21:27 -05:00
If the source location is omitted or set to `null` , Dotbot will use the
basename of the destination, with a leading `.` stripped if present. This makes
2020-06-19 20:28:47 -04:00
the following two config files equivalent.
Explicit sources:
2016-11-18 18:21:27 -05:00
```yaml
- link:
~/bin/ack: ack
~/.vim: vim
~/.vimrc:
relink: true
path: vimrc
~/.zshrc:
force: true
path: zshrc
2018-01-31 18:32:00 -05:00
~/.config/:
2018-04-06 12:29:28 -04:00
glob: true
2018-01-31 18:32:00 -05:00
path: config/*
relink: true
2020-11-22 12:59:30 -05:00
exclude: [ config/Code ]
~/.config/Code/User/:
create: true
glob: true
path: config/Code/User/*
relink: true
2016-11-18 18:21:27 -05:00
```
2020-06-19 20:28:47 -04:00
Implicit sources:
2016-11-18 18:21:27 -05:00
```yaml
- link:
~/bin/ack:
~/.vim:
~/.vimrc:
relink: true
~/.zshrc:
force: true
2018-01-31 18:32:00 -05:00
~/.config/:
2018-04-06 12:29:28 -04:00
glob: true
2018-01-31 18:32:00 -05:00
path: config/*
relink: true
2020-11-22 12:59:30 -05:00
exclude: [ config/Code ]
~/.config/Code/User/:
create: true
glob: true
path: config/Code/User/*
relink: true
2016-11-18 18:21:27 -05:00
```
2019-10-06 01:13:51 -04:00
### Create
Create commands specify empty directories to be created. This can be useful
for scaffolding out folders or parent folder structure required for various
apps, plugins, shell commands, etc.
#### Format
2021-02-25 06:25:17 -05:00
Create commands are specified as an array of directories to be created. If you
want to use the optional extended configuration, create commands are specified
as dictionaries. For convenience, it's permissible to leave the options blank
(null) in the dictionary syntax.
| Parameter | Explanation |
| --- | --- |
| `mode` | The file mode to use for creating the leaf directory (default: 0777) |
The `mode` parameter is treated in the same way as in Python's
[os.mkdir ](https://docs.python.org/3/library/os.html#mkdir-modebits ). Its
behavior is platform-dependent. On Unix systems, the current umask value is
first masked out.
2019-10-06 01:13:51 -04:00
#### Example
```yaml
- create:
- ~/downloads
- ~/.vim/undo-history
2021-02-25 06:25:17 -05:00
- create:
~/.ssh:
mode: 0700
~/projects:
2019-10-06 01:13:51 -04:00
```
2014-10-22 11:10:49 -04:00
### Shell
Shell commands specify shell commands to be run. Shell commands are run in the
base directory (that is specified when running the installer).
#### Format
2015-02-03 11:53:05 -05:00
Shell commands can be specified in several different ways. The simplest way is
2015-04-26 19:52:24 -04:00
just to specify a command as a string containing the command to be run.
Another way is to specify a two element array where the first element is the
shell command and the second is an optional human-readable description.
Shell commands support an extended syntax as well, which provides more
2020-06-19 20:28:47 -04:00
fine-grained control.
| Parameter | Explanation |
| --- | --- |
| `command` | The command to be run |
| `description` | A human-readable message describing the command (default: null) |
| `quiet` | Show only the description but not the command in log output (default: false) |
| `stdin` | Allow a command to read from standard input (default: false) |
| `stdout` | Show a command's output from stdout (default: false) |
| `stderr` | Show a command's error output from stderr (default: false) |
Note that `quiet` controls whether the command (a string) is printed in log
output, it does not control whether the output from running the command is
printed (that is controlled by `stdout` / `stderr` ). When a command's `stdin` /
`stdout` / `stderr` is not enabled (which is the default), it's connected to
`/dev/null` , disabling input and hiding output.
2014-10-22 11:10:49 -04:00
2015-02-10 18:33:37 -05:00
#### Example
2014-10-27 20:04:00 -04:00
```yaml
- shell:
2019-10-06 01:13:51 -04:00
- chsh -s $(which zsh)
- [chsh -s $(which zsh), Making zsh the default shell]
2015-02-03 11:53:05 -05:00
-
command: read var & & echo Your variable is $var
stdin: true
stdout: true
2017-07-12 13:39:36 -04:00
description: Reading and printing variable
2017-07-26 05:03:47 -04:00
quiet: true
2015-02-03 11:53:05 -05:00
-
command: read fail
stderr: true
2014-10-27 20:04:00 -04:00
```
2014-10-22 11:10:49 -04:00
### Clean
Clean commands specify directories that should be checked for dead symbolic
links. These dead links are removed automatically. Only dead links that point
2020-06-19 20:28:47 -04:00
to somewhere within the dotfiles directory are removed unless the `force`
option is set to `true` .
2014-10-22 11:10:49 -04:00
#### Format
Clean commands are specified as an array of directories to be cleaned.
2020-06-19 20:28:47 -04:00
Clean commands also support an extended configuration syntax.
| Parameter | Explanation |
| --- | --- |
| `force` | Remove dead links even if they don't point to a file inside the dotfiles directory (default: false) |
| `recursive` | Traverse the directory recursively looking for dead links (default: false) |
Note: using the `recursive` option for `~` is not recommended because it will
be slow.
2017-03-26 11:30:36 -04:00
2015-02-10 18:33:37 -05:00
#### Example
2014-10-27 20:04:00 -04:00
```yaml
- clean: ['~']
2017-03-26 11:30:36 -04:00
- clean:
2019-12-31 19:14:23 -05:00
~/:
2017-03-26 11:30:36 -04:00
force: true
2019-12-31 19:14:23 -05:00
~/.config:
recursive: true
2014-10-27 20:04:00 -04:00
```
2016-03-02 20:53:19 -05:00
### Defaults
Default options for plugins can be specified so that options don't have to be
repeated many times. This can be very useful to use with the link command, for
example.
2020-06-19 20:28:47 -04:00
Defaults apply to all commands that come after setting the defaults. Defaults
can be set multiple times; each change replaces the defaults with a new set of
2016-03-02 20:53:19 -05:00
options.
#### Format
Defaults are specified as a dictionary mapping action names to settings, which
are dictionaries from option names to values.
#### Example
```yaml
- defaults:
link:
create: true
relink: true
```
2016-02-06 13:54:19 -05:00
### Plugins
Dotbot also supports custom directives implemented by plugins. Plugins are
implemented as subclasses of `dotbot.Plugin` , so they must implement
`can_handle()` and `handle()` . The `can_handle()` method should return `True`
if the plugin can handle an action with the given name. The `handle()` method
should do something and return whether or not it completed successfully.
All built-in Dotbot directives are written as plugins that are loaded by
default, so those can be used as a reference when writing custom plugins.
Plugins are loaded using the `--plugin` and `--plugin-dir` options, using
either absolute paths or paths relative to the base directory. It is
recommended that these options are added directly to the `install` script.
2020-06-19 20:28:47 -04:00
See [here][plugins] for a current list of plugins.
2020-03-25 21:38:39 -04:00
## Command-line Arguments
Dotbot takes a number of command-line arguments; you can run Dotbot with
`--help` , e.g. by running `./install --help` , to see the full list of options.
Here, we highlight a couple that are particularly interesting.
### `--only`
You can call `./install --only [list of directives]` , such as `./install --only
link`, and Dotbot will only run those sections of the config file.
### `--except`
You can call `./install --except [list of directives]` , such as `./install
--except shell`, and Dotbot will run all the sections of the config file except
the ones listed.
2019-10-24 20:39:07 -04:00
## Wiki
2016-03-20 08:34:29 -04:00
Check out the [Dotbot wiki][wiki] for more information, tips and tricks,
user-contributed plugins, and more.
2019-10-24 20:39:07 -04:00
## Contributing
2014-12-20 00:55:17 -05:00
Do you have a feature request, bug report, or patch? Great! See
[CONTRIBUTING.md][contributing] for information on what you can do about that.
2019-10-24 20:39:07 -04:00
## License
2014-03-21 00:48:42 -04:00
2023-03-05 07:37:27 -05:00
Copyright (c) Anish Athalye. Released under the MIT License. See
2014-07-22 23:01:54 -04:00
[LICENSE.md][license] for details.
2014-03-21 00:48:42 -04:00
2018-05-30 09:41:55 -04:00
[PyPI]: https://pypi.org/project/dotbot/
2016-03-26 09:16:41 -04:00
[init-dotfiles]: https://github.com/Vaelatern/init-dotfiles
2015-06-12 00:38:52 -04:00
[dotfiles-template]: https://github.com/anishathalye/dotfiles_template
2017-04-19 13:59:30 -04:00
[inspiration]: https://github.com/anishathalye/dotbot/wiki/Users
2022-12-17 15:12:43 -05:00
[windows-symlinks]: https://learn.microsoft.com/en-us/windows/security/threat-protection/security-policy-settings/create-symbolic-links
2019-02-06 09:30:49 -05:00
[json2yaml]: https://www.json2yaml.com/
2020-06-19 20:28:47 -04:00
[plugins]: https://github.com/anishathalye/dotbot/wiki/Plugins
2016-03-20 08:34:29 -04:00
[wiki]: https://github.com/anishathalye/dotbot/wiki
2014-12-20 00:55:17 -05:00
[contributing]: CONTRIBUTING.md
[license]: LICENSE.md