Learn about Dotfiles

Tram Ho

Ever on a beautiful day, our computer suddenly died. And then we have to reinstall a new operating system, all software and settings for old programs are lost? We spend hours (maybe a whole day) just sitting and reinstalling those programs, then fumbling for the settings again? If you have encountered such cases, DOTFILES is the solution for this case.

1. Concepts

We can understand that Dotfiles is simply a collection of all files with dots at the beginning. However, those files contain the configs of a particular program or system.
These files appear a lot in everyday programming work. Set the environment variable then set in ~ / .bashrc, set ignore git then add gitignore file, … The name “Dotfiles” also starts from the fact that these files always have a “.” at the beginning. It will be hidden by default when we open the folder.

Why should I use Dotfiles?

Even if we don’t know Dotfiles, we can still use a normal computer, so there is no need for Dotfiles. Moreover, even if we have to reinstall the computer, we still have plenty of time to be able to reset the computer, is it necessary to know Dotfiles?
The answer is no. However, Dotfile will bring you a lot of interesting things:

  • Help automate everything possible
  • Create your own config
  • Help learn new things from other people’s configs

In programming there is 1 principle DRY – Don’t repeat yourself – Never repeat something. So make everything automatic. Never re-type config lines, software installation commands, … while we can make it so much simpler. Dotfiles makes it easy to backup, restore or synchronize settings between devices.
In addition, Dotfiles is the place for us to unleash our creativity. We can put in it our stylish configs. Self-installing, key mapping, and adding extend functions will create programs in accordance with our routine and purpose of using the program. This will give you the feeling of being able to control everything as you like, creating a machine for yourself.

During the installation process, we will learn a lot more about how an application will run, learn interesting configs from other people’s dotfiles repo, how to spot problems. problems and solutions, … Solving problems for yourself is a great way to learn new things

2. Structure

Below is an example of the structure of Dotfiles. We will learn about each of its ingredients

.bash_profile

In the Bash shell, this file will be loaded before the Terminal loads its environment, which will contain all of our config, command lines. In this file, we can change various settings such as terminal commands, add aliases to frequently used functions …

.inputrc

Actions on input, key press will be saved in this file. For example

.alias

This file will define shorcuts for the commands. For example:

.functions

If the statement is too complex to create an alias, we can define a function. A function can take parameters at will.

.env

Contains variables usable for other files

Other files

There are many other files that can be used in dotfiles such as:

  • .gitconfig for Git
  • .vimrc for Vim

3. How to customize Dotfiles

Read dotfiles written from others

Each person’s dotfiles have many interesting and useful configs, specific to their work and usage habits. We can read files from others to learn which config is right for us. For example a file is written:

In this file there are many interesting functions, we can easily execute a command without doing any lengthy operations. All of the above functions will be called as a zsh alias.

Write other configs

We can completely write the config for ourselves
For example, the code for today’s weather check in Hanoi:

or quickly translate 1 word by google if you install translate-shell :

or quick lookup on stackoverfolow from terminal with howdoi

Thus, the article has learned the basics of Dotfiles and some ways to use it. Hopefully the article will help everyone to create their own repo Dotfiles, best serve their work and their habits of using computers. See you!

Reference

https://medium.com/@webprolific/getting-started-with-dotfiles-43c3602fd789#.hjk1r1vls
https://www.freecodecamp.org/news/dive-into-dotfiles-part-1-e4eb1003cff6/

Share the news now

Source : Viblo