iTerm ![Iterm2 Iterm2](https://x86.co.kr/files/attach/images/1951610/650/774/002/c183d2621feddc205592491edfb3cbf2.png)
![Iterm2 Zsh Iterm2 Zsh](https://i.stack.imgur.com/E4zcr.png)
The default zsh file (/bin/zsh) saves to.zshhistory in Users/john-doe (home directory) but I am not sure how to with zsh, or iTerm2, set a custom location for that profile's installation of zsh. If anyone could help I'd appreciate that! I spend a fair amount of time in terminal emulators, and here is how I get a good experience on macOS. I use iTerm2, Zsh, and a few cool command-line tools. I am working on macOS, and I prefer the iTerm2 terminal emulator over the macOS Terminal application. My Terminal Setup: iTerm + Zsh. As a follow up to my post on my text editor setup, I wanted to write about the other key part of my development setup - my terminal. Unlike my relatively new text editor setup, my terminal configuration has followed me around for years - spanning over multiple jobs and even more computers. 高逼格终端iTerm2+Oh-My-Zsh自动连接远程服务器 解决rz/sz卡死 【亲测-完美】 晚上下班坐地铁,偶然间看到一个帖子,关于【Mac上你值得拥有的app】才知道有iTerm2,从下载,到美化.
Iterm2 Zsh Alias
ZSH productivityThis post is about the two tools I use regularly in my development environment: iTerm and oh-my-zsh. iTerm is a mac terminal replacement and zsh + oh-my-zsh is an excellent combo to replace the bash shell with some cool stuffs.
Here, we'll see how to achieve some productivity improvements by effectively using these tools.
iTerm #
As I said already, iTerm is a mac terminal replacement. It comes with ton of features missing in default terminal. Below, you will see some of them which made me choose iTerm.
Multiple tabs and split screens
Often we have to work with multiple terminals. iTerm support splitting the current terminal panes vertically/horizontally and adding any number of tabs. The shortcuts for splitting the terminal is
CMD+D
( for vertical ) and CMD+SHIFT+D
( for horizontal ).For adding a new tab, the shortcut is
CMD + T
( same like your browser ).Auto-complete menu
iTerm has a pretty cool drop-down menu for auto-completion. Graphics for iwork 3 1 1. Press
CMD+;
from the terminal and you can see the autocomplete dropdown showing the completion.Show paste history
iTerm also keeps a buffer of the previous paste history. You can see the paste history in a dropdown menu by pressing the keys
CMD+SHIFT+H
Find the cursor
Once you start working with multiple split panes and tabs, sometimes it's hard to find where your cursor is. Press the key combination
CMD+/
and iTerm will highlight where your cursor is. Pretty smart, huh ?Search all tabs ( aka Expose tabs )
This is another feature excites me when I have to work with so many tabs or panes. It is hard to move from one tab/pane to another pane when not sure where exactly it is. iTerm can expose all the tabs for you with the key combination
CMD+OPTIONS+E
and then you can search for the tab.This is not the end; iTerm has lot of features, but this post is not enough for explaining all of them. For the complete set of iTerm features, check this link.
ZSH + Oh-My-ZSH #
Like iTerm, ZSH is the default bash shell replacement; and Oh-my-zsh is the framework built for configuring the zsh shell. It also provides extending the framework with custom plugins. This can be done by adding them into the .zshrc file.
From their documentation:
Let's say you if you want to add a plugin foobar to your configuration.
edit the ~/.zshrc file. then add to
plugins=(git bundler foobar)
edit the ~/.zshrc file. then add to
plugins=(git bundler foobar)
I found some these oh-my-zsh plugins extremely useful in my daily tasks:
The Z plugin
One of my all time favourite plugin. The Z plugin remembers your navigation history in the terminal, and auto completes it for you next time. For example, after enabling the
z
plugin, if I do this:The
z
plugin remembers this navigation and the next time I just need to type the following and press TAB
See
z
in action:The H plugin
The
H
plugin lists all your previous command history right there. Sometimes it is easy to see all of them and select the desired one. Enable the h
plugin by adding it to the plugin section of .zshrc.Then, type
h
in the command prompt and enter.Git Plugin
This plugin provides a set of git aliases to oh-my-zsh. I use this a lot everyday and I think I might've forgotten the original git commands now :). Just kidding, this is a wonderful plugin that saves a lot of my time. See the below image to know how I usually work with these aliases.
I am sure that once you start using this plugin, you won't look back. You can find the complete zsh git cheatsheet here in this link
Zsh syntax highlighting plugin
Fish shell like syntax highlighting in your zsh shell. See any of the GIF images, you can observe that the command syntax color changes as when I type.
Read more : https://github.com/zsh-users/zsh-syntax-highlighting
Iterm2 + Zsh
Open PR from command line
I haven't played around with this plugin much. I included this because I think this might be useful to some of you.
Basically, when you call open-pr, the function will verify if you are working on a fork (by convention, you have an upstream remote), then, it will open your browser in the correct URL so you can just hit the Create Pull Request button.
The
take
commandOne of my favourite shortcut command provided by Oh-my-zsh. Basically, what the
take
command does is to create a directory and change the path to it. So instead of doing the following:I could just do:
That's really nice !
Everything else: https://github.com/unixorn/awesome-zsh-plugins
Antigen for ZSH #
Antigen is a simple tool to manage the zsh environment. I recently started using Antigen and it seems a better option for installing plugins and all.
Antigen is a small set of functions that help you easily manage your shell (zsh) plugins, called bundles. The concept is pretty much the same as bundles in a typical vim+pathogen setup. Antigen is to zsh, what Vundle is to vim.
Find more about Antigen here: https://github.com/zsh-users/antigen.
Summary #
Effectively using tools saves a lot of time and improves productivity. I hope these tips are useful to you. Feedbacks are welcome.
I spend a fair amount of time in terminal emulators, and here is how I get a good experience on macOS.I use iTerm2, Zsh, and a few cool command-line tools.
iTerm2
I am working on macOS, and I prefer the iTerm2 terminal emulator over the macOS Terminal application:
I especially enjoy the ability to split panes horizontally and vertically, as well as the keyboard shortcuts to move around.
I use the minimal theme with the tab bar on top and the status bar in the bottom with a few helper icons like CPU usage and current process.The color theme is Dracula.I like this theme very much also in other tools, notably Visual Studio Code which is my currently preferred editor aside from IntelliJ IDEA for Java projects.I also use the Cascadia font from Microsoft which is my preferred monospace font these days.
Dot files
Everyone has their preferences for managing dot files.
I am using a simple repository for that, with a bill-of-materials for applications to install automatically: https://github.com/jponge/dotfiles/tree/2019 (the 2019 edition, switch to another branch if you want).
The dot files get sym-linked using GNU Stow.For instance
~/.zshrc
points to ~/dotfiles/home/.zshrc
.There are various environment variables and shell functions that I rely on.They can be found in
~/dotfiles/env
, and they get loaded from ~/.zshrc
(or ~/.bash_profile
if you prefer Bash) using a simple for-loop:Oh My Zsh
There exist several Zsh plugin managers, but if you want something with sensible defaults and batteries included then Oh My Zsh is a no-brainer.
Once you have it installed, you will open
~/.zshrc
and start tweaking the configuration.It is very likely that you will start with the theme ?![Iterm2 Iterm2](https://x86.co.kr/files/attach/images/1951610/650/774/002/c183d2621feddc205592491edfb3cbf2.png)
I personally like the default
robbyrussell
, but you can also use a random theme and eventually find something you like better:Next come the plugins, and this is all about the tools that you need to use on daily basis.Check
~/.oh-my-zsh/plugins/
to see all the plugins that come with Oh My Zsh.I personally have the following plugins in use, more on them in the next sections:
I’d recommend not having too many plugins in use.You can often replace a plugin with loading a Zsh completion from the tool.
fzf, a command-line fuzzy finder
You will have to install the tool for the corresponding Oh My Zsh plugin to work, so go to https://github.com/junegunn/fzf.
This tool will help your for completions. A lot ?
Syntax highlighting
This external plugin provides syntax highlighting as you type shell commands, much like the Fish shell would do.This is very useful, especially since you get instant feedback on non-existing commands, etc.
Head over to https://github.com/zsh-users/zsh-syntax-highlighting for installation instructions, aka:
Auto-suggestions
There is another useful plugin for having a Fish-like experience with completion suggestions based on past history.
Go to https://github.com/zsh-users/zsh-autosuggestions for more details, or simply run:
Misc. useful command-line tools
![Iterm2 Zsh Iterm2 Zsh](https://i.stack.imgur.com/E4zcr.png)
There are a bunch of command-line tools that I use but that not everyone may know.
Mac Iterm2 Zsh
- HTTPie is great for doing HTTP requests. It comes with syntax highlighting and sensible ways to pass form fields, JSON data, files, etc. It is much better that
cURL
in a development context. pstree
to list processes as a parent-child tree. This is not installed by default on macOS.- bat is similar to
cat
, except it offers syntax highlighting (and other goodies). - watchexec is a general-purpose tool to watch files and trigger a command in response to changes.
- dive is a tool for exploring Docker images, and especially see what each layer brings to the filesystem.
- foreman is a tool for running multiple processes. You just specify commands in a
Procfile
, and then start them all and check their logs. It is very useful in development when you need to start many processes. - hub is the GitHub command-line tool for interacting with repositories. It is especially useful for checking out pull-requests.
- plantuml is a fantastic tool for generating all sorts of diagrams from… text.
- jabba is a tool for managing Java virtual machines. It is frequently updated with builds of OpenJDK, Azul Zulu, GraalVM, Amazon Corretto, OpenJ9, etc.
Iterm2 Zsh Theme
Edited: December 3rd 2019
Since I wrote that post I came across further great command-line tools and tips ?
- kube-ps1 adds current Kubernetes context and namespace to the shell prompt.I do not enable it by default and I have a function ready when I need to enable it:
- htop is a replacement for
top
with a much much improved user interface. - fd is a modern alternative to
find
. - noti executes a command and sends a notification when done.This is very useful when running a long build, an upload, etc.
- ag is a code search tool that can replace
grep
in many situations.
I also added some aliases to simplify my
kubectl
usage:Iterm Shell Integration
Finally my growing usage of
bat
instead of cat
has prompted me to define the following environment variables to have more sensible defaults: