Dotfiles
Summary
What & Why
A dotfile is any file that starts with a dot. Configurations for apps and systems are stored in them. For example, most text editors will have a dotfile to store settings such as how many spaces a tab should trigger. One of the most common ways developers use dotfiles is for their scripting language of choice. My examples will be for the Bash shell language.
Aliases
Aliases are custom shortcuts assigned to commands you use in the terminal, or command line. They follow a very specific syntax alias shortcutName="originalCommand"
. You can make one directly in the command line, but to create a permanent alias, put it in an alias dotfile with the name .aliases, and link that to your main bash dotfile, .bashrc, with the function below.
for file in ~/.{path,bash_prompt,aliases,functions}; do [ -r "$file" ] && [ -f "$file" ] && source "$file"; done; unset file;
Functions
Functions are similar to aliases. They are in a dotfile named .functions, and consist of creating shortcuts to run a command. Yet, functions can be more complex than aliases, and perform multiple actions. They have a similar syntax to functions in JS. function name() { commands }
.
Resources I've Found Helpful
Cheat Sheet
Create a dotfile
touch .bashrc
Refresh bash to see changes
source ~/.bashrc
Aliases
After setting up the following aliases running c in your terminal will be the same as running clear, and so on
alias c="clear"
alias ll="ls -lha"
alias gs="git status"
alias ga="git add"
alias gc="git commit -m"
Functions
Make a directory and navigate to it
function mkd () {
mkdir -p "$@" && cd "$@"
}
Congratulate yourself with a happy dance
function happydance {
echo ' ┏(-_-)┛ ┗(-_- )┓ ┗(-_-)┛ ┏(-_-)┓'
}
Dotfiles Projects
Create your own dotfiles
Take a look at some dotfile repositories, and start creating your own aliases and functions. Start small, add new ones as you work on projects, and don't be afraid to be creative. If using bash, you will want .bashrc, .bash_profile, .bash_prompt, .aliases, and .functions
files.
Create a dotfiles repo
Create a repo on GitHub or any other similar service, and add your dotfiles to the repo. Then you will be able to pull them down for any new system you're on, and it's a helpful way to practice making commits.