DEV Community

spO0q
spO0q

Posted on • Edited on

Do you have a dotfiles repository?

As dev, it's not uncommon to use different machines or to renew laptops and devices. You don't want to spend too much time in repetitive operations, such as setting git, defining custom aliases, etc.

To speed up install, you can store these configurations in a git repository (often called dotfiles by convention).

In such repository, you will likely add .bashrc, .zshrc, .gitconfig, .gitignore_global, etc. It's way more convenient for new install and maintenance.

In addition, you may include a small script to copy each file at the root of the $HOME folder, so you won't have to do it manually:

#!/usr/bin/env zsh
# Credit: Julien maury

target="$PWD/files"

echo "Copying files..."
cd $target
for entry in $(ls .??*)
do
  cp $entry $HOME
  echo "$entry copied!"
done
echo "Done!"
cd -
Enter fullscreen mode Exit fullscreen mode

The script goes at the root of the repository and all dotfiles in a subfolder called files:

├── files
│   ├── .bashrc
│   ├── .zshrc
│   ├── .gitconfig_global
│   └── .gitconfig
└── install.zsh
Enter fullscreen mode Exit fullscreen mode

To use the repo, you may run git clone DOTFILES_REPO_URL && cd DOTFILES_REPO && zsh install.zsh.

This approach works best if you keep the same operating system, so you might encounter some issues when switching between Windows, Linux, and Mac, but those incompatibilities tend to be less and less frequent.

Top comments (6)

Collapse
 
jcubic profile image
Jakub T. Jankiewicz

I have such repo, but just a note if you don't have such repo you don't write aliases by hand, if you do you're doing wrong. You always have some kind of dot files that you copy from computer to computer. If you're using Linux for a long time you have a lot of stuff. dotfile repo just make this simpler.

I have my own repo, but I need to move the rest of my configs there github.com/jcubic/dotfiles since that is not all what I have.

Collapse
 
hayden profile image
Hayden Rouille

Yep, I just need to get around to writing some ansible scripts to set everything up since I swap linux distros every now and then for some fun!

Collapse
 
miniscruff profile image
miniscruff

github.com/miniscruff/dotfiles yup, I created a little python generator to take JSON files and build shell scripts to bootstrap new machines

Collapse
 
heyhusen profile image
Husen • Edited

I always use chezmoi to manage my dotfiles.

Collapse
 
spo0q profile image
spO0q

If you prefer using ready-to-go solutions that's not a less valuable approach, and I'm sure it handles everything.

This post is a light demo.