View source on GitHub
João Paulo Cercal

PHP Developer at GetYourGuide GmbH in Berlin, Germany

  • 772 words
  • 4 min read
  • Others

iTerm2 + Zplug = Productivity

After spending a long time of my life using the normal terminal I met a new tool called iTerm2 because a friend of mine a few years ago. And, this week I’ve discovered the power of zplug. So, here’s a brief tutorial on how to get something looking similar to this:

iTerm2 + zplug

iTerm2

This is a tool like the native app for terminal provided by Apple that has a lot of features that you can just check here. It allows you to customize everything from autocomplete to syntax highlight.

But the most interesting feature for me is called Split Panes.

Cmd ⌘ + D split pane vertically

iTerm vertical split

Cmd ⌘ + Shift + D split pane horizontally

iTerm horizontal split

Colors scheme

To continue with the customization of your terminal we’ll install the One Dark color scheme in your iTerm app.

1
git clone -b master --depth=1 https://github.com/bahlo/iterm-colors.git ~/iterm-colors

This command will download some presets including One Dark theme. In order to install it on iTerm press Cmd ⌘ + I and go to Colors > Color Presets > Import..., there you can select the preset that you would like to import.

Note that the presets are living inside of the directory ~/iterm-colors/colors/*.itermcolors.

iTerm color presets

Meslo Font

Another thing to install is a good font, I’m using Meslo if you want the same you can install doing this:

1
git clone https://github.com/powerline/fonts.git && cd fonts && ./install.sh

And, to use this font on iTerm press Cmd ⌘ + I and to go Text > Change Font > Family > Meslo LG L for Powerline. Don’t forget to disable the option Use a different font for non-ASCII text.

iTerm text configuration

Zplug

It’s a Zsh Plugin Manager like oh-my-zsh, prezto and antigen.

Some advantages according to the project page:

  • Can manage everything
    • Zsh plugins/UNIX commands on GitHub and Bitbucket
    • Gist files (gist.github.com)
    • Externally managed plugins e.g., oh-my-zsh and prezto plugins/themes
    • Binary artifacts on GitHub Releases
    • Local plugins
    • etc. (you can add your own sources!)
  • Super-fast parallel installation/update
  • Support for lazy-loading
  • Branch/tag/commit support
  • Post-update, post-load hooks
  • Dependencies between packages
  • Unlike antigen, no ZSH plugin file (*.plugin.zsh) required
  • Interactive interface (fzf, peco, zaw, and so on)
  • Cache mechanism for reducing the startup time

This is a framework for managing your zsh configuration. In order to install this tool, you should run this command:

1
brew install zplug

My configuration file ~/.zshrc

This is the configuration file that I’m using now. To be able to use this one you must install this dependencies before proceed:

1
2
3
pip install psutil
pip install powerline-shell
brew install peco

Now, copy and paste this content to your ~/.zshrc file.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
###########################################################
# Pre configuration

# Define the environment variable ZPLUG_HOME 
export ZPLUG_HOME=/usr/local/opt/zplug

# Loads zplug
source $ZPLUG_HOME/init.zsh

# Clear packages
zplug clear

###########################################################
# Packages

zplug "zsh-users/zsh-syntax-highlighting"
zplug "zsh-users/zsh-autosuggestions"
zplug "zsh-users/zsh-completions"
zplug "paulmelnikow/zsh-startup-timer"
zplug "tysonwolker/iterm-tab-colors"
zplug "desyncr/auto-ls"
zplug "momo-lab/zsh-abbrev-alias"
zplug "rawkode/zsh-docker-run"
zplug "arzzen/calc.plugin.zsh"
zplug "peterhurford/up.zsh"
zplug "jimeh/zsh-peco-history"
  
###########################################################
# Theme

zplug "b-ryan/powerline-shell"

function powerline_precmd() {
    PS1="$(powerline-shell --shell zsh $?)"
}

function install_powerline_precmd() {
  for s in ${precmd_functions[@]}; do
    if [ "$s" = "powerline_precmd" ]; then
      return
    fi
  done
  precmd_functions+=(powerline_precmd)
}

if [ "$TERM" != "linux" ]; then
    install_powerline_precmd
fi

###########################################################
# Install packages that have not been installed yet
if ! zplug check --verbose; then
    printf "Install? [y/N]: "
    if read -q; then
        echo; zplug install
    else
        echo
    fi
fi

zplug load

###########################################################
# Post configuration

# Aliases
abbrev-alias -g G="| grep"

# Docker images
function npm() {
  run_with_docker "node" "alpine" "npm" [email protected]
}

function go() {
  run_with_docker "golang" "latest" "go" [email protected]
}

function php() {
  run_with_docker "php" "latest" "php" [email protected]
}

This file will be loaded each time that you start a new session using your terminal, so during the next session you should see a question there because you don’t have the plugins yet Install? [y/N]:, after the installation you should be able to have a terminal like I have here.

Let me know if you have questions about this process.

Note that the focus of this tutorial was to have it working on OSX but I’m pretty sure that’s possible to have the same environment running on Linux or Windows but without iTerm since this app is just available for OSX.