How to configure zsh

Over the years of using Linux as my primary and only OS I had to embrace some
unavoidable facts. First, things tend to change and complex things tend to
break. Second, reinventing the wheel almost never pays off. And finally, it’s
not that hard to make a new habit and sometimes it’s better than adjusting your
workstation to your “intuitive” understanding that may change very soon.

So years ago I decided to only use the most common software and only the very
minimal personalized configuration on top of it.

I mostly need two applications, no matter what OS or desktop environment I run
- a terminal and a web browser.

Terminal

This is the only GUI app you actually need if you work as a developer. Whether
you edit sources, debug, read Hacker News, answer your emails, chat, listen to
music - most of the time you will be staring into this utterly boring window of
your terminal. So let’s make it work fast and look good.

In terms of performance there are two primary choices here: xterm and
st. Both are very small and lightweight, xterm comes with X server by
default, st needs to be compiled manually, but since you are a developer that
should not scare you.

I will go with xterm here, but I have also been using st for many years and
have absolutely no regrets about it.

As for the visual aesthetics, there’s not much UI in the terminal - it’s a
rectangle with monospace text after all. You can adjust colors and you can
adjust the font.

Adjusting colors is now easier than ever. There is a special web
page where you can find a ready-to-use color scheme, see it in
action and copy the configuration into ~/.Xresources. I ended up using
“Eighties” theme, and it seems to be popular these days. Solarized or Molokai
are also good alternatives.

On Ubuntu there might be a catch that generated configuration snippet uses
*.color0 wildcard, while the way Ubuntu loads .Xresources requires you to
replace it with XTerm.vt100.color0. Fortunately, this can be easily done in
almost any text editor.

For the fonts I find Roboto Mono and Ubuntu Mono fairly good, but you may have
a different taste.

My resulting .Xresources looks like this (it only tweaks font rendering, sets
font and colors, and allows Alt key to be used in Tmux or vim shortcuts):

Reboot (or log out + log in) to apply the new configuration and your terminal
is good to do.

zsh

UNIX Shell is my primary user interface to everything. And despite fish is
really cool and modern, or rc is so simple and nicely implemented, I tend to
stick to Bash or Zsh.

I’m still looking at backporting my zsh config to bash, but at the moment I’m a
Zsh user. Zsh is more user-friendly and more advanced, but it’s never the
default shell and it also can be slow. For example, there is a wonderful
oh-my-zsh project that allows you to build zsh config from the pieces, but
it’s not uncommon when the shell start up time raises to 3 seconds or even
slower.

I try to keep my .zshrc as small as possible. I am using only 3 zsh modules
- autocompletion, colors and VCS info:

autoload -U compinit colors vcs_info
colors
compinit

Then I set up general zsh options and history:

I like when my shell keeps a lot of history. I also want to remember only one
line for each command and ignore certain commands that I prefix with a
whitespace (Bash can do it, too, so I’d better make a habit to put a whitespace
than set up complex shell rules for that). Finally, I want zsh to correct my
typos.

# Report command running time if it is more than 3 seconds
REPORTTIME=3
# Keep a lot of history
HISTFILE=~/.zhistory
HISTSIZE=5000
SAVEHIST=5000
# Add commands to history as they are entered, don't wait for shell to exit
setopt INC_APPEND_HISTORY
# Also remember command start time and duration
setopt EXTENDED_HISTORY
# Do not keep duplicate commands in history
setopt HIST_IGNORE_ALL_DUPS
# Do not remember commands that start with a whitespace
setopt HIST_IGNORE_SPACE
# Correct spelling of all arguments in the command line
setopt CORRECT_ALL
# Enable autocompletion
zstyle ':completion:*' completer _complete _correct _approximate

The next thing to set up is shell prompt.

propmt

Shell prompt should be concise and informative. I believe that colors and
unicode symbols are the way to go.

I use vcsinfo module to provide information about git repos (as well as hg,
svn, csv as a bonus). I use bindkey -v to enable vi editing mode. I dropped
in a few functions to start with insert mode by default and to re-evaluate
prompt on each command.

This gives me a very minimal prompt that looks like this:

minor notes

I also have a few more lines in my zshrc that bind/fix common keys for
home/end/delete. And I also added one and only alias to have colored output in ls: