markdown 使用iTerm和ZSH作为终端更换
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 使用iTerm和ZSH作为终端更换相关的知识,希望对你有一定的参考价值。
# Use iTerm and ZSH as Terminal Replacement
[Setup](https://hackernoon.com/make-your-terminal-more-colourful-and-productive-with-iterm2-and-zsh-11b91607b98c), [iTerm ColorScheme](https://iterm2colorschemes.com/), [ZSH Theme](https://github.com/robbyrussell/oh-my-zsh/wiki/Themes),
First install [Homebrew](https://docs.brew.sh/Installation.html)
## 1. Install iTerm2:
Next install iTerm2 with this:
```
# install iTerm
brew cask install iterm2
```
## 2. Install `zsh` and `Oh My zsh`:
Then install the `zsh`, an alternative to bash. The alternative to `~/.basrc` is `~./zshrc`, which you add extra scripts to that run when loading the terminal. (Mac OSX already come with `zsh` but it is really outdated, we use the version from brew instead):
```
# install zsh
brew install zsh
```
[Oh my zsh](https://github.com/robbyrussell/oh-my-zsh) is a framework for managing your `zsh` configuration. To install it use the below command:
```
# install oh my zsh
curl -L http://install.ohmyz.sh | sh
```
## 3. Install syntax highlighting:
One of the cool things you can add with it is [syntax highlighting](https://github.com/zsh-users/zsh-syntax-highlighting):
```
# add syntax highlighting
cd ~/.oh-my-zsh && git clone git://github.com/zsh-users/zsh-syntax-highlighting.git
echo 'source ~/.oh-my-zsh/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh' >> ~/.zshrc
```
## 4. Install iTerm theme:
Now to install theme for iTerm, go to [iTerm ColorScheme](https://iterm2colorschemes.com/) and download the `zip` file. To install, follow this:
- Launch iTerm 2. Get the latest version at iterm2.com
- Type CMD+i
- Navigate to Colors tab
- Click on Load Presets
- Click on Import
- Select the `.itermcolors` file(s) of the scheme(s) you'd like to use
- Click on Load Presets and choose a color scheme.
Current favorite themes are these one:
```
- Earthsong (current one with swapped Green Normal - Cyan Bright and modified cursor color).
- Afterglow.
- Birds Of Paradise.
- Fideloper.
- Later This Evening.
- Sea Shells.
- Sea Foam Pastel.
- Slate.
```
## 5. Other Setting for iTerm:
Add this to `~/.zshrc` so that it can recognize your existing alias and environment path:
`source ~/.bash_profile`
To change default open iTerm window size go to `Preferences > Profile > Window > Setting for new Window` and increase `Columns` and `Rows`.
To hide scrollbar go to `Preferences > Appearance > Hide Scrollbars`.
## 6. Change zsh theme to `Powerlevel9k`:
To change `zsh` theme go to [Oh My ZSH theme](https://github.com/robbyrussell/oh-my-zsh/wiki/Themes) or [zsh theme](https://zshthem.es/all/).
But for now we will use [Powerlevel9k](https://github.com/bhilburn/powerlevel9k/wiki/Install-Instructions#step-1-install-powerlevel9k):
```
# install powerlevel9k theme
git clone https://github.com/bhilburn/powerlevel9k.git ~/powerlevel9k
echo 'source ~/powerlevel9k/powerlevel9k.zsh-theme' >> ~/.zshrc
```
In order for `Powerlevel9k` to work, we need to install [Nerd font](https://github.com/ryanoasis/nerd-fonts). We will use the patched [Source Code Pro Regular](https://github.com/ryanoasis/nerd-fonts/tree/master/patched-fonts/SourceCodePro).
Download this file (download all if necessary):
[Sauce Code Pro Nerd Font Complete.ttf](https://github.com/ryanoasis/nerd-fonts/blob/master/patched-fonts/SourceCodePro/Regular/complete/Sauce%20Code%20Pro%20Nerd%20Font%20Complete.ttf)
Double click and select `Install`. After that select it in:
```
iTerm -> Preferences -> Profiles -> Text -> Font -> Change Font
```
After that add this line to `~/.zshrc` [SOURCE](https://github.com/bhilburn/powerlevel9k/wiki/Install-Instructions#option-4-install-nerd-fonts):
```
POWERLEVEL9K_MODE='nerdfont-complete'
```
## 7. Customize Powerlevel9k:
[SOURCE](https://github.com/bhilburn/powerlevel9k)
Add these to `~/.zshrc`:
```
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(user dir rbenv vcs)
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
```
**NOTE:** All these theme settings should be called before setting the theme or it wont take effect, example:
```
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(user dir rbenv vcs)
POWERLEVEL9K_SHORTEN_DIR_LENGTH=2
source ~/powerlevel9k/powerlevel9k.zsh-theme
```
以上是关于markdown 使用iTerm和ZSH作为终端更换的主要内容,如果未能解决你的问题,请参考以下文章
macOS下iTerm2+zsh+oh-my-zsh+powerlevel10k打造最强终端
为MAC配置终端环境iTerm2+Zsh+oh-my-zsh
Mac OS 终端美化:iterm2 + zsh + oh~my~zsh 设置教程