Package: dotfiles-sync
dotfiles-syncdotfiles-sync is a command line application which helps manage configuration files (typically dotfiles) across different machines and operating systems.dotfiles-syncMotivationGetting StartedlistsyncupdateOtherDisabling ItemsFiltering ItemsEnvironment VariablesMotivationI 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 StartedThis package is deployed topypi:python-mpipinstalldotfiles-syncThe--helpwill always show the most up to date options:❯dotfiles--help
usage:dotfiles[-h][-cCONFIG][-wCONFIG_DIR][-d][-i][-fFILTER[FILTER...]][--version]{list,sync,update}...

positionalarguments:{list,sync,update}optionalarguments:-h,--helpshowthishelpmessageandexit-cCONFIG,--configCONFIGdotfilesconfiguration.Pointstotargetlocations.-wCONFIG_DIR,--config_dirCONFIG_DIRLocationoftheconfigurationfilestosync-d,--dryOnlyreadandshowmewhatyouwouldhavedone-i,--interactiveBeforedoingawrite,askforconfirmation-fFILTER[FILTER...],--filterFILTER[FILTER...]keys(s)oftheconfigurationtoapply.Ifnotsetthenapplythemall--versionshowprogram'sversionnumberandexitThis 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"}}}Typically nameddotfiles-sync.json, this file defines each of the configurations we are interested in along with the locations where they should live per operating system. In this example we have a single entry.bashrcwhich states that we have a file in the root of theconfiguration directorywith the same name. Theconfiguration directoryis the directory where the central authority of that files live (typically a git repository which contains all your configuration files).This entry can also be a folder or file within a subdirectory (e.gbash/.bashrc) for if you wanted to keep all your bash related configuration files organised into abashfolder in your repo.Each entry 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 inplatform.systembut lowercased. Paths are also expanded usingos.path.expanduserwhich means special symbols like~will be expanded in both Window and Linux.Note if you have a path which can be applied across platforms, then you can define a single config"cross": "~/.bashrc".listOnce you have a dotfiles configuration and configuration directory you can runlist:❯dotfiles--configexamples/dotfiles-sync.json--config_direxamples/configslist[18:58:55]INFOListingConfigurationsINFO.bashrc:examples/configs/.bashrc=>/home/kiran/.bashrc(ConfigurationMatchStatus.SYNCHRONIZABLE|ConfigurationFileType.FILE)INFO.vimrc:examples/configs/.vimrc=>/home/kiran/.vimrc(ConfigurationMatchStatus.SYNCHRONIZABLE|ConfigurationFileType.FILE)INFOpgcli:examples/configs/pgcli=>/home/kiran/.config/pgcli(ConfigurationMatchStatus.SYNCHRONIZABLE|ConfigurationFileType.DIRECTORY)SYNCHRONIZABLEmeans it looks like it is possible to synchronise this file andFILEtells us the type of synchronize it's going to do (as oppsosed toDIRECTORYwhich will do a recursive copy).syncIf we are happy, then we can do async. This will take the files in your configuration directory and allow them to the machine.❯dotfiles--configexamples/dotfiles-sync.json--config_direxamples/configssync[18:59:41]INFOCopyingFileexamples/configs/.bashrc=>/home/kiran/.bashrcINFOCopyingFileexamples/configs/.vimrc=>/home/kiran/.vimrcINFOCopyingDirectoryexamples/configs/pgcli=>/home/kiran/.config/pgcli
SyncingConfiguration...━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━100%0:00:00updateYou may want to also do the reverse and update your configuration directory with the files on your current machine. This can be done usingupdate:❯dotfiles--configexamples/dotfiles-sync.json--config_direxamples/configsupdate[19:01:47]INFOCopyingFile/home/kiran/.bashrc=>examples/configs/.bashrcINFOCopyingFile/home/kiran/.vimrc=>examples/configs/.vimrcINFOCopyingDirectory/home/kiran/.config/pgcli=>examples/configs/pgcli
UpdatingConfigurationDirectory:examples/configs━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━100%0:00:00OtherDisabling ItemsConfiguration Items can be disabled from being applied within the config file.{"config":{"zsh/.p10k.zsh":{"linux":"~/.p10k.zsh","disabled":true}}}Filtering ItemsBy default dotfiles will assume you want to run configuration on all items (unless explictelydisabled). 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]INFOCopyingFile/home/kiran/projects/dotfiles/bash/.profile=>/home/kiran/.profileINFOCopyingFile/home/kiran/projects/dotfiles/pgcli/config=>/home/kiran/.config/pgcli/configSyncingConfiguration...━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━100%0:00:00Environment VariablesIt can be cumbersome to type out / remember where your dotfiles directory is on each machine. There are two environment variables to make life easier which you can set on a system level:exportDOTFILESSYNC_CONFIG=# path to the dotfiles-sync.jsonexportDOTFILESSYNC_DIR=# path to your dotfiles which should be syncedThis means makes invocation of this dotfiles-sync much cleaner:dotfilessync