Home Using Dotfiles
Post
Cancel

Using Dotfiles

On *nix system, dotfiles are normally associated with hidden files, in this case, dotfiles are important files that hold your different configurations. Many advanced system users use these files to standardize their computer builds and store them on GitHub. This makes it easy to migrate to a new machine and remove the stress from having your computer die on you and having to rebuild from scratch without remembering all the configs you’ve made over time.

An example of a dotfile would be your profile configuration, these are stored in a file named either .bash_profile, .bashrc, .zsh_profile or .zshrc that resides in your home directory. If you use git any, you will know about the configuration file git uses, .gitconfig

how do you know if you have the configurations? Easy:

  • Browse to the directory you want to check, normally your home cd ~ to make sure you are there, then:
    1
    
    ls -lah
    

You should see output like this:

1
2
3
4
5
6
7
8
drwxr-xr-x user user 1.7 KB Mon Jan 24 18:52:47 2022 .
drwxr-xr-x root root 256 B  Wed Jan  1 02:00:00 2020 ..
drwxr-xr-x user user 256 B  Mon Dec 20 14:46:03 2021 .config
drwx------ user user 384 B  Thu Jan 13 16:47:48 2022 Desktop
drwx------ user user 608 B  Fri Jan 21 19:09:47 2022 Documents
drwx------ user user 5.4 KB Fri Jan 21 20:23:53 2022 Downloads
.rw-r--r-- user user 2.3 KB Mon Dec  6 13:10:52 2021 .vimrc
.rw-r--r-- user user 2.6 KB Tue Jan 11 14:18:42 2022 .zshrc

If you’re on a mac and want to do similar in Finder, just press ⌘ Cmd+⇧ Shift+. , to go back to normal, just repeat the sequence.

How do I create them?

Each person may handle this differently but the majority or those that do use dotfiles, host them in the ~/.dotfiles directory

Create your .dotfile direcotry:

1
mkdir ~/.dotfiles

Create the files you want to use:

1
touch ~/.dotfiles/.aliases  ~/.dotfiles/.exports

You can also add your .zshrc there as well for example, but that needs some extra steps that I won’t cover here as I only use this for my aliases and exports primarily. There are lots of examples on Github.

Add this to your .zshrc file:

1
2
3
# Source custom and private aliases, env vars, functions
[[ -f ~/.dotfiles/.aliases ]] && source ~/.dotfiles/.aliases
[[ -f ~/.dotfiles/.exports ]] && source ~/.dotfiles/.exports

How do I use them

As a quick example of what you cna do with this is, for example, in your aliases file. You know how on macs, you always get those psky .DS_Store files that helps you finds things fast on your machine? Well, those can sometimes slip into your work and because they’re hidden they are easily ignored until you push to git or share and someone asks what that is doing.

This is a great way to be able to clean up your working directory without having to load finder and going to each folder to see if they exist.

1
alias cleanupDS="find . -type f -name '*.DS_Store' -ls -delete"

Now all you have to do is in a terminal, cd into the directory you want to scan and clean and run cleanupDS and you’re good to go.

To do

I’ll post the contents of my file in a repo later and add a link here once I do.

This post is licensed under CC BY 4.0 by the author.