20

I work on several different machines. I have a lot of specific things I like my shell to, or the prompt to look like, or aliases, etc.

What do you think the best way to keep all my machines shells to act the same?

First off, I'm aware that different machines will need different paths to bins and other differences, so my first inclination is to just include a file at the end of my profile, this is the one that we'll keep in sync.

What is the best way to keep files synced up? I can put the file on a remote system, and perhaps use git, to push, then pull my changes every once in a while. However, isn't Rsync better suited for this?

5 Answers5

30

This is how I do it:

  1. I never put real content on the ~/.bashrc or ~/.bash_profile files, instead those files are just symlinks to the real configuration files kept in a subdirectory in my home folder, for example ~/dotfiles/bashrc and ~/dotfiles/bash_profile.

  2. I keep the ~/dotfiles folder under source control using Git, and hosted at GitHub.com

  3. When I install a new system, I just clone the GitHub repository to a new local ~/dotfiles folder and create all the symlinks (currently by hand, though this step should be easy to automate).

  4. I use this same procedure for other config files, like .hgrc (for Mercurial), .vimrc and several others.

  5. Whenever I edit one of the configuration files, I just commit and push to GitHub, and then pull in every other machine.

This is still somewhat laborious and manual, but I've been happy with it.

This is the current content of my ~/dotfiles folder:

~/dotfiles
|-- bash
|   |-- aliases
|   |-- config
|   |-- env
|   `-- promptcolors
|-- bash_profile
|-- bashrc
|-- gitconfig
|-- gvimrc
|-- hg-templates
|   |-- map-cmdline.dlog
|   |-- map-cmdline.nlog
|   |-- map-cmdline.sglog
|   `-- map-cmdline.slog
|-- hgrc
|-- ssh
|   `-- config
|-- vim
|   |-- after
|   |-- colemak-mappings.vim
|   |-- colors
|   |-- doc
|   |-- filetype.vim
|   |-- ftplugin
|   `-- plugin
`-- vimrc

I stole this idea from the great Peepcode Advanced Command line screencast (worth the $9 in my opinion).

And this is where I keep my GitHub repository, in case you want to take a look. Don't expect anything of great interest, I'm just a bash/command line newbie.

http://github.com/sergio/dotfiles

8

For all the people still trying to find the best solution for this problem, there is now a very actively maintained tool that does everything you need and more:
https://github.com/lra/mackup

It goes far beyond syncing zsh or bash profiles. It can sync settings of a large amount of tools. Essentially, it uses the same symlink concept as the accepted answer but automates it so you only ever need two commands:

  1. mackup backup
  2. mackup restore
  • last update 19 days ago so it's current too, nice find – jcollum Oct 24 '21 at 18:47
  • Mackup is great, but just be really careful with how you configure it. By default it will copy all your config files containing secrets, API keys and passwords for things like: kubectl docker mvn. If that's what you want then fine, but just know that you should never use it to backup to a public git repo. – simon Aug 03 '22 at 11:08
3

There are a number of different tools that will accomplish this goal

Or see the big list of all things dotfiles related at http://dotfiles.github.io/

(Full disclosure: I am the original author of Hermit and still one of the primary maintainers)

Zefira
  • 131
1

Use Dotty to securely store your configuration files and easily keep them in-sync across your machines.

0

I think that https://github.com/fsquillace/kyrat does what you need.

It is a very lightweight ssh wrapper which does not need root access or any installations to the remote host.

A simple a example of usage:

$> echo "alias q=exit" > ~/.config/kyrat/bashrc
$> kyrat myuser@myserver.com
myserver.com $> q
exit