The Definitive Guide: Zsh and Dotfiles.

In this article, I will show you these contents.
- How to install
zsh - How to setup
- What’s the “dotfiles”
Who should read this article?
The main targets of the article are
- Who willing to customize the terminal
- Who wants to get familiar with the terminal
- Who’d like to be more effective in the terminal
- Who doesn’t know about
zshor dotfiles
If you are already well known about zsh and terminal, this article is not for you.
About zsh
First of all, let’s take a brief look at what is zsh. zsh is defined as below.
“Zsh is a powerful shell that operates as both an interactive shell and as a scripting language interpreter. While being compatible with the POSIX sh (not by default, only if issuing emulate sh), it offers advantages such as improved tab completion and globbing.”
Simply put, zsh is a kind of interactive shell, like
- bash
- fish
- csh
- Nu Shell
and so on.
I guess almost all of you, the target of this article, are currently using bash or zsh now, because these two are (or were) used as the default shells for Linux and Mac OS X. Here, the difference between bash and zsh is that zsh is something like extended-bash. So, if you are using bash without custom settings, you can move on to zsh easily. If you’d like to know the exact differences, you can google it.
How to install zsh
Ok, now you know what is zsh , let’s move on to how to install it.
If you are a mac user, you can do it with brew .
brew install zshIf you are using Linux, package managers will do it.
sudo apt install zsh
# or
sudo yum install zshConfirm the installation
If the installation is done, you can check it by using which command.
which zsh
# -> /usr/bin/zshDid it!! You are almost there!
Set zsh as the login shell
Next, let’s set zsh as your login shell. To do so, first, let’s confirm that your /etc/shells has the path of zsh .
# checking /etc/shells
cat /etc/shells# If there are no line related zsh, you should add it
sudo sh -c "echo $(which zsh) >> /etc/shells"If you’d like to use some shell as a login shell, you have to add the path of the shell to /etc/shells .
Next, you can set the shell by using chsh (change shell) command.
chsh -s $(which zsh)
Done! Now you can see these outputs below after log-out and log-in and open terminal.
This is the Z Shell configuration function for new users,
zsh-newuser-install.
You are seeing this message because you have no zsh startup files
(the files .zshenv, .zprofile, .zshrc, .zlogin in the directory
~). This function can help you with a few settings that should
make your use of the shell easier.You can:(q) Quit and do nothing. The function will be run again next time.(0) Exit, creating the file ~/.zshrc containing just a comment.
That will prevent this function being run again.(1) Continue to the main menu.(2) Populate your ~/.zshrc with the configuration recommended
by the system administrator and exit (you will need to edit
the file by hand, if so desired).--- Type one of the keys in parentheses ---Of course, you can choose what you like, but here, let’s Type “q” to quit the screen and create the configuration file by yourself.
Creating .zshrc
The next step is to configure the zsh . You can do it by creating ~/.zshrc. This file is equivalent to ~/.bashrc in bash. You can define the way of completion, where to store command history, and so on in the file. You can see the detailed document in the links below.
I know it is hard to write your own zshrc file from scratch. So I recommend you copy-and-pasting first, and then, modify it as you like.
Here is the part of my .zshrc. Let’s copy and paste it to make your initial .zshrc. Save the .zshrc file in your home directory.
################################# HISTORY #################################
# history
HISTFILE=$HOME/.zsh-history # file to save history
HISTSIZE=100000 # history size in-memory
SAVEHIST=1000000 # history size in the file# share .zshhistory
setopt inc_append_history # save the command to history when running
setopt share_history # share history with other session################################# COMPLEMENT ################################# # enable completion autoload -Uz compinit && compinit
zstyle ':completion:*' matcher-list '' 'm:{[:lower:]}={[:upper:]}' '+m:{[:upper:]}={[:lower:]}'
zstyle ':completion:*' format '%B%F{blue}%d%f%b'
zstyle ':completion:*' group-name ''zstyle ':completion:*:default' menu select=2
################################# OTHERS #################################
# automatically change directory when dir name is typed
setopt auto_cd# disable ctrl+s, ctrl+q
setopt no_flow_controlAfter saving the file, you can load it by the following command.
source ~/.zshrcIf the setting has done correctly, the tab completion will be work as shown below.

OK! Now you learn how to customize your zsh!
Dotfiles
The next topic is “Dotfiles”.
In the previous section, you made your original .zshrc. I know you are already a fan of zsh, so you will edit your setting file again and again. In such a case, you’d like to put it under the version control system.
The word “Dotfiles” means the idea of using git (or other VCS) to organize setting files like .zshrc. You can organize not only .zshrc but also like
.vimrc.tmux.conf
and so on. Using dotfiles is very easy. All you have to do is,
- 1. put the config files in a directory.
- 2.
git init - 3. Create the file to deploy these setting files.
Let’s do it together!
1. put the config files in a directory
First, you have to create a directory to store the setting files.
mkdir ~/dotfilesNow you have the directory named “dotfiles” in your home directory. Then, move your .zshrc to the directory.
mv ~/.zshrc ~/dotfiles# confirm
ls -la ~/dotfiles
# -> you could see .zshrc2. git init
The second task is to make it a Git directory.
cd ~/dotfiles
git init
git add .zshrc
git commit -m "init"That it! Now you can try any setting you want and revert it easily thanks to Git. I recommend you make a GitHub repository for a remote one.
3. Create the file to deploy these setting files.
Now your .zshrc is in ~/dotfiles, so your zsh can not find your setting file as ~/.zshrc anymore. Let’s resolve the problem by creating a symbolic link to ~/.zshrc. You can make it by using ln command.
ln -sv ~/dotfiles/.zshrc ~/
# Confirm
ls -la ~/
# -> you could see the symlinkYou can make the file to deploy your setting file like below.
#!/bin/bash
dotfiles = (.zshrc)for file in "$dotfiles[@]"; do
ln -svf $file ~/
doneMake the file with upper content and name it ~/dotfiles/deploy.sh. By running this script, you can make the symbolic link automatically. Don’t forget to add it to Git!
Conclusion
In this article, you learned
- How to install
zsh - How to setup
- What’s the “dotfiles”
Now you can customize your zsh!
And here is my dotfiles repository.
Let’s enjoy your terminal life!






