iTerm2 + zsh + oh-my-zsh macOS上最强大的终端功能

iTerm2 + zsh + oh-my-zsh

你在默认终端纠结吗?希望你的终端看起来像这样吗?默认终端很糟糕?

如果你想让你的终端看起来像上图。来吧,这篇会适合你。

安装Homebrew

iTerm2

打开终端并粘贴。

1
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

下载iTerm2

为什么我们必须将默认的macOS终端替换为iTerm2?

  1. 转到下载页面https://www.iterm2.com/downloads.html
  2. 下载后,将文件拖放到我们的Application文件夹。

安装zsh

打开终端并粘贴。

1
brew install zsh

我们需要“oh-my-zsh”

img

Oh-My-Zsh is an open source, community-driven framework for managing your ZSH configuration. It comes bundled with a ton of helpful functions, helpers, plugins, themes, and a few things that make you shout…

–“Oh My ZSH!”

安装oh-my-zsh

安装时,oh-my-zsh将自动用zsh替换默认终端。

打开终端并粘贴。

1
sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

使用颜色装饰 iTerm2

img

  1. 打开终端并粘贴
1
2
$ cd Downloads
$ curl -O https://raw.githubusercontent.com/MartinSeeler/iterm2-material-design/master/material-design-colors.itermcolors
  1. 打开已在第一部分下载的 iTerm2

  2. 转到 iTerm2 > Preferences > Profiles > Colors

  3. 单击右下角的 Color Presets…

  4. 单击 Import…

  5. 选择 material-design-colors.itermcolors 文件

  6. Load Presets… 选择 material-design-colors

管理插件

插件维基页面:https://github.com/robbyrussell/oh-my-zsh/wiki/Plugins

在这种情况下,我想在我的zsh上启用插件’docker’,所以我将运行此命令

1
vi~ / .zshrc

并键入“/ plugin”(不带引号)按Enter键,键入“i”字符并插入要添加的插件。

1
2
3
4
5
6
7
8
9
10
.
.
.
# 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
)

在这种情况下,我将添加docker插件,只需在我们的括号中添加“docker”。

1
2
3
4
5
6
7
8
9
10
11
.
.
.
# 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
docker
)

在您满意后,按Esc并键入:wq,这意味着您保存文件并立即退出。并重启iTerm2。

添加别名(永久别名)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
vi ~/.zshrc
.
.
.
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
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"

如果我输入 dkps ,它将执行 docker ps

您的支持将鼓励我继续坚持技术分享!
0%