Boost Your Productivity By Using The Terminal (iTerm & ZSH)
Using the terminal is one of the biggest productivity boosts you can gain in your daily work as a developer. If you know your shortcuts, you will be way faster than using the mouse. In this article, I want to show you my terminal setup and how I use it on a daily basis. The cover image shows my current setup in action.
I am a macOS user so the article is mainly focused on this operating system but most of the software I demonstrate is also available for Windows and Linux users.
Install Homebrew
Homebrew is the missing package manager for macOS (or Linux) and makes installing packages super easy.
To install it on macOS you just need to paste this command in your terminal:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
After that you should be able to run brew
, you can check the successful installation by running brew -v
in your terminal:
1▶ brew -v
2Homebrew 2.2.4
3Homebrew/homebrew-core (git revision 22532; last commit 2020-01-31)
4Homebrew/homebrew-cask (git revision 19d828; last commit 2020-01-31)
iTerm2
I would recommend replacing the default Terminal.app
in macOS by iTerm2.
You can install it using brew
:
brew install --cask iterm2
Some of the best iTerm features:
- Split your terminal into multiple panes which you can switch by hotkeys
- Register a hotkey that brings the terminal to the foreground when you're in another application
- A robust find-on-page feature
- Different user profiles to save your window arrangements and more
- Paste history that shows everything you’ve pasted into the terminal
- and many more
ZSH and Oh My ZSH
Since macOS Catalina (10.15.2) the default shell is now ZSH instead of Bash. You can enrich ZSH by using the Oh My ZSH framework which provides some functionality that will boost your productivity:
- Autocompletion by pressing
Tab
key which allows selecting available directories, commands and files. - Use alias commands, you can get a list of all available alias by running
alias
in your terminal - You can omit the
cd
(change directory) command:..
(instead ofcd ..
),../..
(instead ofcd ../..
)/
(for root directory) and~
(for home directory) take
command creates a new directory and changes the path to it. Example:take testFolder
is the same asmkdir testFolder && cd testFolder
- Use
-
to quickly navigate between your last and current path - Many cool themes
- A list of amazing plugins
- Git integration
- And many more...
You can install it using this terminal command:
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
Oh My ZSH
can be configured via the .zshrc
configuration file:
vi ~/.zshrc
My .zshrc
configuration looks similar to this one:
1# If you come from bash you might have to change your $PATH.
2export PATH=$HOME/bin:/usr/local/bin:$PATH
3
4export JAVA_HOME="/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home/"
5
6# jenv
7export PATH="$HOME/.jenv/bin:$PATH"
8eval "$(jenv init -)"
9
10# Path to your oh-my-zsh installation.
11export ZSH=/Users/mhoffman/.oh-my-zsh
12
13# Set name of the theme to load. Optionally, if you set this to "random"
14# it'll load a random theme each time that oh-my-zsh is loaded.
15# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
16ZSH_THEME="avit"
17
18# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
19# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
20# Example format: plugins=(rails git textmate ruby lighthouse)
21# Add wisely, as too many plugins slow down shell startup.
22plugins=(
23 git
24 brew
25 docker
26 npm
27 osx
28 bgnotify
29 zsh-syntax-highlighting
30 zsh-autosuggestions
31 web-search
32)
33
34source $ZSH/oh-my-zsh.sh
35
36# Set personal aliases, overriding those provided by oh-my-zsh libs,
37# plugins, and themes. Aliases can be placed here, though oh-my-zsh
38# users are encouraged to define aliases within the ZSH_CUSTOM folder.
39# For a full list of active aliases, run `alias`.
40
41alias zshconfig="nano ~/.zshrc"
42alias ohmyzsh="nano ~/.oh-my-zsh"
43alias gpf='git push -f'
44
45# Docker alias
46alias dkps="docker ps"
47alias dkst="docker stats"
48alias dkpsa="docker ps -a"
49alias dkimgs="docker images"
50alias dkcpup="docker-compose up -d"
51alias dkcpdown="docker-compose down"
52alias dkcpstart="docker-compose start"
53alias dkcpstop="docker-compose stop"
54
55# Kubectl alias
56alias kdev='kubectl -n dev'
57alias kpg='kubectl -n playground'
58alias ktest='kubectl -n test'
59alias kprod='kubectl -n prod'
60alias kpreprod='kubectl -n preprod'
I use the avit theme but there are many other cool themes available.
Some words about the used plugins, here you can find a list of all available Oh My ZSH
plugins:
- git: provides many aliases and a few useful functions for git.
- brew: adds several aliases for common brew commands.
- docker: adds auto-completion for docker.
- npm: provides completion as well as adding many useful aliases for npm.
- osx: provides a few utilities for OSX.
- bgnotify: cross-platform background notifications for long running commands
- web-search: adds aliases for searching with Google, Wiki, Bing, YouTube and other popular services.
- zsh-autosuggestions: suggests commands as you type based on history and completions
- zsh-syntax-highlighting: provides syntax highlighting for the shell zsh, red for invalid and green for valid commands:
Use Material Theme
I really like Material Design so I also use it in iTerm thanks to this iTerm2 color scheme. Installation instructions can be found here.
The result should look similar to my terminal:
Use Minimal Theme
Choose Minimal theme to have a cleaner UI with smaller tabs as shown in the screenshot above:
Change font to Cascadia Font
I use the Cascadia Font from Microsoft in iTerm. After installing the font on your operating system you need to select it as a font in your iTerm profile:
Good CLI tools
In this chapter I want to demonstrate some CLI tools which I regularly use in my terminal and which can highly increase your productivty:
- lazygit: a simple but amazing terminal UI for git commands
- HTTPie: a command line HTTP client with an intuitive UI, JSON support, syntax highlighting, wget-like downloads, plugins, and more which I often use instead of graphical programs like Postman or Insomnia
- htop: "an interactive process viewer for Unix systems", which I use instead of the macOS
Activity Monitor.app
- Midnight Commander: a visual file manager
- tree: List contents of directories in tree-like format
- bat: a
cat
clone with syntax highlighting and Git integration - lnav: an advanced log file viewer
- kubectl: Kubernetes command-line tool to run commands against Kubernetes clusters
- watch: Linux watch command, which is really helpful to run commands at a regular interval
Free course
I highly recommend the free Command Line Poweruser course from Wes Bos if you want to learn more about ZSH.
Conclusion
I am still at the beginning of my terminal journey but I really enjoy it so far. Using the terminal more often I could reduce the time I need to grab my mouse and many operations can be done much faster using the CLI than using a graphical interface. And of course, you look like a cool hacker even if you are just browsing directories.
Let me know what useful CLI tools you are using and what productivity tips you can share with me and the community.
Manually Lazy Load Modules And Components In Angular
In Angular enterprise applications, it is often a requirement to load a configuration from a server via HTTP request which contains a UI configuration. Based on this configuration data, multiple modules and/or components need to be lazy-loaded and its routes dynamically added to the application.
Sending Message To Specific Anonymous User On Spring WebSocket
In my current, I had the opportunity to develop a new application based on Vue.js in the frontend and Spring Boot in the backend. The backend should send updates to the frontend via a WebSocket connection so that users do not need to refresh the website to see the latest information.