Translation: Increase your productivity by using the terminal (iTerm2 & Oh my ZSH)

Insert picture description here
Using the terminal is one of the biggest productivity gains in your daily work as a developer. If you know the shortcut, you will be faster than using the mouse. In this article, I want to show you my terminal settings and how I use it every day. The cover image shows my current settings.

I am a macOS user, so this article focuses on this operating system, but most of the software I demonstrate is also suitable for Windows and Linux users.

Install homebrew

Homebrew is the missing package manager for macOS (or Linux) that makes installing packages super easy.

To install it on macOS, just paste the following command in the 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 run brew -v in the terminal to check whether the installation is successful:

▶ brew -v
Homebrew 2.2.4
Homebrew/homebrew-core (git revision 22532; last commit 2020-01-31)
Homebrew/homebrew-cask (git revision 19d828; last commit 2020-01-31)

iTerm2

I recommend replacing the default value in Terminal.appmacOS with iTerm2 .

You can install it using brew:

brew install --cask iterm2

Some of the best features of iTerm:

  • Divide your terminal into multiple panes, you can switch by hotkey
  • Register a hotkey to bring the terminal to the foreground when you are in another application
  • Powerful page search function
  • Different user profiles can save your window arrangement, etc.
  • Paste history, showing all the content you have pasted into the terminal
  • And more

ZSH and Oh My ZSH

Starting with macOS Catalina (10.15.2), the default shell is now ZSH instead of Bash. You can enrich ZSH with the Oh My ZSH framework, which provides some productivity-enhancing features:

  • Through the Tab button for automatic completion, you can select the available directories, commands and files.
    Insert picture description here
  • Using the alias command, you can aliasget a list of all available aliases by running in the terminal
  • You can omit cd(change directory) commands: ( ..replace cd ..), ../..(replace cd ../..) /(for root directory) and ~(for home directory)
  • takeThe command creates a new directory and changes its path. Example: take testFolderwithmkdir testFolder && cd testFolder
  • Use -your last and current path to quickly navigate
  • Many cool themes
  • Amazing list of plugins
  • Git integration
  • There are a lot more…

You can install it using the following terminal command:

sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

Oh My ZSHIt can be .zshrcconfigured through the configuration file:

vi ~/.zshrc

My .zshrcconfiguration looks similar to this:

# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:$PATH

export JAVA_HOME="/Library/Java/JavaVirtualMachines/openjdk-11.0.2.jdk/Contents/Home/"

# jenv
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"

# Path to your oh-my-zsh installation.
export ZSH=/Users/mhoffman/.oh-my-zsh

# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="avit"

# Which plugins would you like to load? (plugins can be found in ~/.oh-my-zsh/plugins/*)
# Custom plugins may be added to ~/.oh-my-zsh/custom/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(
  git
  brew
  docker
  npm
  osx
  bgnotify
  zsh-syntax-highlighting
  zsh-autosuggestions
  web-search
)

source $ZSH/oh-my-zsh.sh

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.

alias zshconfig="nano ~/.zshrc"
alias ohmyzsh="nano ~/.oh-my-zsh"
alias gpf='git push -f'

# Docker alias
alias dkps="docker ps"
alias dkst="docker stats"
alias dkpsa="docker ps -a"
alias dkimgs="docker images"
alias dkcpup="docker-compose up -d"
alias dkcpdown="docker-compose down"
alias dkcpstart="docker-compose start"
alias dkcpstop="docker-compose stop"

# Kubectl alias
alias kdev='kubectl -n dev'
alias kpg='kubectl -n playground'
alias ktest='kubectl -n test'
alias kprod='kubectl -n prod'
alias kpreprod='kubectl -n preprod'

I use the avit theme , but there are many other cool themes .

Some words about used plugins, here you can find Oh My ZSHa list of all available plugins:

  • git: Git that provides many aliases and some useful features .
  • brew: Add several aliases for commonly used brew commands.
  • docker: Add auto-completion function for docker .
  • npm: Provide completion functions and add many useful aliases to npm .
  • osx: Provides some utilities for OSX.
  • bgnotify: Cross-platform background notification for long-running commands
    Insert picture description here
  • Web search: Add aliases for searching through Google, Wiki, Bing, YouTube and other popular services.
  • zsh-autosuggestions : suggest entering commands based on historical records and completion
    Insert picture description here
  • zsh-syntax-highlighting : Provide syntax highlighting for shell zsh, red means invalid, green means valid command:
    Insert picture description here
    Insert picture description here

Use material theme

I really like Material Design, so because of this iTerm2 color scheme , I also used it in iTerm. Installation instructions can be found here .

The result should be similar to my terminal:
Insert picture description here

Use minimal theme

Choose "Minimal Theme" to make the interface cleaner and the labels smaller, as shown in the screenshot above:
Insert picture description here

Change font to Cascadia font

I use Microsoft's Cascadia font in iTerm. After installing the font on the operating system, you need to select it as the font in the iTerm configuration file:
Insert picture description here

Good CLI tool

In this chapter, I want to demonstrate some CLI tools that I often use in the terminal. These tools can greatly increase your productivity:

  • lazygit : simple but amazing terminal UI for git commands

Insert picture description here

  • HTTPie : Command line HTTP client with intuitive UI, JSON support, syntax highlighting, downloads like wget, plugins, etc. I often use them instead of graphical programs such as Postman or Insomnia
    Insert picture description here
  • htop : "Interactive process viewer for Unix systems", I used it instead of macOSActivity Monitor.app
    Insert picture description here
  • Midnight Commander : Visual file manager
    Insert picture description here
  • tree : List the contents of the directory in a tree format
    Insert picture description here
  • bat : cat clone with syntax highlighting and Git integration

Insert picture description here

  • lnav : Advanced log file viewer
    Insert picture description here
  • kubectl : Kubernetes command line tool, used to run commands on Kubernetes clusters
  • watch : Linux watch command, which is very helpful for running commands regularly

Free course

If you want to learn more about ZSH, I highly recommend Wes Bos to provide a free Command Line Poweruser course.

in conclusion

I'm still at the beginning of the terminal journey, but I really like it so far. Using the terminal more frequently can reduce the time to hold the mouse, and using the CLI can complete many operations faster than using the graphical interface. Of course, even if you just browse the catalog, you look cool.

Let me know what useful CLI tools you are using and what productivity tips you can share with me and the community.

reference

https://www.mokkapps.de/blog/boost-your-productivity-by-using-the-terminal-iterm-and-zsh/

Guess you like

Origin blog.csdn.net/zgpeace/article/details/114555916