Skip to main content

Manages dotfile configuration files across operating systems

Project description

dotfiles-sync

Deploy pypi

dotfiles-sync is a command line application which helps manage configuration files (typically dotfiles) across different machines and operating systems.

Motivation

I needed a solution which would allowed me to easily automate synchronising my configuration files as I jump between different machines which could be either Windows or Linux.

Getting Started

This package is deployed to pypi:

python -m pip install dotfiles-sync

The --help will always show the most up to date options:

 dotfiles --help
usage: dotfiles [-h] [-c CONFIG] [-w CONFIG_DIR] [-d] [-i] {list,sync,update} ...

positional arguments:
  {list,sync,update}

optional arguments:
  -h, --help            show this help message and exit
  -c CONFIG, --config CONFIG
                        dotfiles configuration. Points to target locations.
  -w CONFIG_DIR, --config_dir CONFIG_DIR
                        Location of the configuration files to sync
  -d, --dry             Never actually write any files, only read and show me what you would have done
  -i, --interactive     Before doing a write, ask for confirmation

This application relies on the fact that you store your configuration in source control and that you define a configuration file which declares your configurations you want to track along with paths per operating system.

An example of a configuration file is:

{
    "config": 
    {
        ".bashrc": 
        {
            "linux": "~/.bashrc",
            "windows": "~/.bashrc"
        }
    }
}

Where .bashrc is the file in the configuration directory we are interested in tracking. The configuration directory is the directory where the central authrority of that file lives (typically a git repository which contains all your configuration files). This key could also be directory e.g bash/.bashrc if you wanted to keep all your bash related configuration files in organised into a bash folder.

Each key contains paths to operating system specific path the file should be syncronised into. The operating systems supported here are the same as the ones that come in platform.system but lowercased. Paths are also expanded using os.path.expanduser which means special symbols like ~ will be expanded in both Window and Linux.

list

Once you have a dotfiles configuration and configuration directory you can run list:

 dotfiles --config examples/config.json --config_dir examples/configs list
[18:58:55] INFO     Listing Configurations
           INFO     .bashrc: examples/configs/.bashrc => /home/kiran/.bashrc (ConfigurationMatchStatus.SYNCHRONIZABLE | ConfigurationFileType.FILE)
           INFO     .vimrc: examples/configs/.vimrc => /home/kiran/.vimrc (ConfigurationMatchStatus.SYNCHRONIZABLE | ConfigurationFileType.FILE)
           INFO     pgcli: examples/configs/pgcli => /home/kiran/.config/pgcli (ConfigurationMatchStatus.SYNCHRONIZABLE | ConfigurationFileType.DIRECTORY)

SYNCHRONIZABLE means it looks like it is possible to synchronise this file and FILE tells us the type of synchronize it's going to do (as oppsosed to DIRECTORY which will do a recursive copy).

sync

If we are happy, then we can do a sync. This will take the files in your configuration directory and allow them to the machine.

 dotfiles --config examples/config.json --config_dir examples/configs sync

[18:59:41] INFO     Copying File examples/configs/.bashrc => /home/kiran/.bashrc
           INFO     Copying File examples/configs/.vimrc => /home/kiran/.vimrc
           INFO     Copying Directory examples/configs/pgcli => /home/kiran/.config/pgcli
Syncing Configuration... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00

update

You may want to also do the reverse and update your configuration directory with the files on your current machine. This can be done using update:

 dotfiles --config examples/config.json --config_dir examples/configs update

[19:01:47] INFO     Copying File /home/kiran/.bashrc => examples/configs/.bashrc
           INFO     Copying File /home/kiran/.vimrc => examples/configs/.vimrc
           INFO     Copying Directory /home/kiran/.config/pgcli => examples/configs/pgcli
Updating Configuration Directory: examples/configs ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00

Other

Disabling Items

Configuration Items can be disabled from being applied within the config file.

{
  "config":
  {
    "zsh/.p10k.zsh": 
    {
            "linux": "~/.p10k.zsh",
            "disabled": true
    }
  }
}

Filtering Items

By default dotfiles will assume you want to run configuration on all items (unless explictely disabled). If you would like to only apply certain configurations then you can pass the keys of the configs you want to --filter:

 dotfiles -c $HOME/projects/dotfiles/dotfiles-sync.json  --filter "bash/.profile" "pgcli/config" -w $HOME/projects/dotfiles/ sync

[14:54:59] INFO     Copying File /home/kiran/projects/dotfiles/bash/.profile => /home/kiran/.profile                                                                                                                
           INFO     Copying File /home/kiran/projects/dotfiles/pgcli/config => /home/kiran/.config/pgcli/config                                                                                                     
Syncing Configuration... ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dotfiles-sync-0.0.10.tar.gz (8.8 kB view details)

Uploaded Source

Built Distribution

dotfiles_sync-0.0.10-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file dotfiles-sync-0.0.10.tar.gz.

File metadata

  • Download URL: dotfiles-sync-0.0.10.tar.gz
  • Upload date:
  • Size: 8.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

File hashes

Hashes for dotfiles-sync-0.0.10.tar.gz
Algorithm Hash digest
SHA256 afe071007fbee62860bd65ae530cb244a54163309d57f719c7b1bee642c3ff8e
MD5 14b240b3da6dcc81cb1db3891c5f4d43
BLAKE2b-256 080fd30599a878f5a09c5e543622b07fb7e9168d72a1b7c9ce22a2470990df3e

See more details on using hashes here.

File details

Details for the file dotfiles_sync-0.0.10-py3-none-any.whl.

File metadata

  • Download URL: dotfiles_sync-0.0.10-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.54.1 CPython/3.9.1

File hashes

Hashes for dotfiles_sync-0.0.10-py3-none-any.whl
Algorithm Hash digest
SHA256 e868d72739ff569e7a2e7ed458c2e3169d1dacc0b59b753933bfd18832c359c8
MD5 c833f5fea768f769719e9138404cff4d
BLAKE2b-256 6611a90798e8a3faafcc1f0ea8c2e5d9a9fa8a76a8961e48b3f7c537b447f6bb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page