This repository contains the source code for dotfilers
, a dotfile management utility written in Rust.
You can either grab the latest release or build it yourself:
$ cargo build --release
You will find the binary in target/release/dotfilers
.
Add the binary to your path, and you are ready to go!
By default, when invoking dotfilers
it will look for a dotfilers.yaml
file in the current directory. However, you can specify a custom file by using -c/--config PATH
. Keep in mind that the current working directory will be used for calculating relative paths.
When you are testing some configurations, you can pass -d/--dry-run
in order not to perform any actual operation. If invoked in dry-run mode, dotfilers will print the operations that would be executed, but won't actually perform any operation.
Also, in case you only want to apply some of your dotfilers.yaml
sections, you can pass the section names as arguments. Let's say you only want to execute your nvim
and ssh
sections. In order to do so, you can run dotfilers nvim ssh
.
You can have a .dotfilers
section in your dotfilers.yaml
that will configure behaviours for the dotfilers
binary.
Here you can find an example with the default values:
```yaml .dotfilers: # Log level for the dotfilers binary # Must be one of: # - trace # - debug # - info # - warn # - error log_level: info
# Strategy to use in case of conflict (the file that would be created already exists) # Must be one of: # - abort (the program will stop) # - overwrite (the already existing file/directory will be removed) # - rename-old (the already existing file/directory will be renamed to NAME.bak, and in case it also exists, .bak1, .bak2...) conflict_strategy: rename-old
# Shell that will be used for 'run' directives shell: /bin/bash -c ```
In the root of your dotfilers.yaml
you can specify the different sections you want to manage.
A section starts with a name, and then a list of operations to be performed. Here you can find an example of all the available operations:
```yaml
zsh: # Create a symlink from zsh/.zshrc to ~/.zshrc - linkfrom: zsh/.zshrc linkto: ~/.zshrc
# Only if the os is linux, create a symlink from zsh/.zshrc.linux to ~/.zshrc.local - ifos: linux linkfrom: zsh/.zshrc.linux link_to: ~/.zshrc.local
# Only if the os is darwin, create a symlink from zsh/.zshrc.linux to ~/.zshrc.local - ifos: darwin linkfrom: zsh/.zshrc.darwin link_to: ~/.zshrc.local
ssh: # Only if the os is linux: # - use the template on ssh/config.tpl # - fill it using the vars from ssh/varslinux # - store the result at ~/.ssh/config - ifos: linux template: ssh/config.tpl templateto: ~/.ssh/config vars: ssh/varslinux
# Only if the os is darwin: # - use the template on ssh/config.tpl # - fill it using the vars from ssh/varsdarwin # - store the result at ~/.ssh/config - ifos: darwin template: ssh/config.tpl templateto: ~/.ssh/config vars: ssh/varsdarwin
# Copy all files that match idrsa* from the ssh folder into ~/.ssh/ - copyfrom: ssh/idrsa* copyto: ~/.ssh/
nvim: # As this section is too long, run the contents of nvim/deploy.yaml - include: nvim/deploy.yaml
extra: # Run inline code - run: echo "abc" > /tmp/abc
# Run multiple commands - run: | echo "some_contents" >> /tmp/abc echo "Other contents" >> /tmp/abc
# You can even invoke other programs/scripts - run: /usr/bin/python3 -c "print('a' * 127)" > /tmp/lotsofas ```
Here you can find a detailed list of all the directives that are supported.
Please notice that if you declare multiple options in the same directive entry (such as link_from
, link_to
, copy_from
, copy_to
) the resulting operation does not have any guarantee of being consistent, so please avoid doing so.
Copy files or directories from one location to another. This command supports globs in the copy_from
section.
Sections:
copy_from
: Which file / directory to be copied.
ssh/id_rsa*
or directory/*.txt
.copy_to
: Where to copy the files.
copy_from
is a single file, please also write the desired destination filename (such as: copy_to: ~/.ssh/authorized_keys
).copy_from
is a glob, you should use the path to the destination directory (such as: copy_from: directory/*.txt
and copy_to: ~/data
).Link files or directories from one location to another. This command supports globs in the link_from
section.
Sections:
link_from
: Which file / directory to be symlinked.
ssh/id_rsa*
or directory/*.txt
.link_to
: Where to symlink the files.
link_from
is a single file, please also write the desired destination filename (such as: link_to: ~/.ssh/authorized_keys
).link_from
is a glob, you should use the path to the destination directory (such as: link_from: directory/*.txt
and link_to: ~/data
).You can also generate files on the fly by filling templates. dotfilers
uses Tera as a templating engine, so please refer to the Tera documentation for templates.
In order to define variables, you can create a file with any name you want, and fill the variables with the following format:
``` variable1=value1
variable2=value2 ```
There are some variables that are filled by dotfilers
itself. For now these variables are:
dotfilers_os
: The current OS. May either be linux
or darwin
.You can run arbitrary commands with dotfilers
.
There is no better documentation that some examples:
```yaml
Keep in mind that if the exit status code is not 0, the execution will abort.
For very long sections it may be handy to delegate the directives into another file. dotfilers
supports doing so by using the include
directive.
The included files must have the same structure as the dotfilers.yaml
file, so that means you will need to wrap your directives into a section.
```yaml
nvim: - include: nvim/directives.yaml
nvim: - if_os: linux run: echo "This is linux" ```
``` MIT License
Copyright (c) 2022 Carlos Quintana
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ```