终端zsh
by rajaraodv
通过rajaraodv
只需七个步骤,即可使您的“ ZSH”终端站起来—直观指南 (Jazz Up Your “ZSH” Terminal In Seven Steps — A Visual Guide)
In this blog I’ll cover installing ITerm2, ZSH shell, “oh my ZSH”, Themes, ITerm2 color schemes, “oh my ZSH” plugins and enable “ligature” support to help create a beautiful and powerful Terminal.
在此博客中,我将介绍安装ITerm2,ZSH shell,“ oh my ZSH”,主题,ITerm2配色方案,“ oh my ZSH”插件,并启用“连字”支持以帮助创建美观而强大的终端。
If you want to just make your regular Bash Terminal powerful, take a look at my previous blog: “Jazz Up Your Bash Terminal”. But ZSH explained in this blog is more powerful stuff.
如果您只是想让常规的Bash Terminal功能强大,请看一下我以前的博客:“ Jazz Up Your Bash Terminal ”。 但是ZSH在此博客中解释的是更强大的功能。
摘要: (Summary:)
We’ll be covering a lot of things. This may be confusing, so here is the summary of what we will be doing.
我们将介绍很多内容。 这可能会造成混淆,所以这里是我们将要做的摘要。
- Install ITerm2 — This is a better alternative to the default Terminal 安装ITerm2-这是默认终端的更好替代方案
- Install latest ZSH shell — This is more powerful than the regular bash shell. We will switch ITerm2 to use ZSH shell. 安装最新的ZSH shell-比常规的bash shell更强大。 我们将ITerm2切换为使用ZSH shell。
- Install “Oh My ZSH “— This is a CLI tool to easily configure ZSH and add themes and plugins to ZSH 安装“哦,我的ZSH”-这是一个CLI工具,可轻松配置ZSH并将主题和插件添加到ZSH
- Add two types of Themes using “Oh My ZSH” — some themes need extra steps so we will cover both 使用“哦,我的ZSH”添加两种类型的主题-一些主题需要额外的步骤,因此我们将涵盖这两种主题
- Install different ITerm2 Schemes — These are just color schemes for the UI 安装不同的ITerm2方案-这些只是UI的颜色方案
- Add two different Plugins using “Oh My ZSH” to improve productivity 使用“ Oh My ZSH”添加两个不同的插件以提高生产力
Enable “ligature” support so when you write an arrow =>;, it appears like a real arrow →
启用“结扎”的支持,所以当你写一个箭头=>;,它看起来像一个真正的ARR O w制备→
第1步-安装ITerm2 (Step 1— Install ITerm2)
A lot of programmers like ITerm2 instead of the default Terminal. It is similar to the Terminal, but has lots of features of its own. It of course can run ZSH, Bash, and other shells inside it.
许多程序员喜欢ITerm2而不是默认的Terminal。 它类似于终端机,但具有许多自身功能。 它当然可以在其中运行ZSH,Bash和其他Shell。
The following video shows some of the new features of Item 2 (v3).
以下视频显示了第2项(v3)的一些新功能。
For this blog we’ll use ITerm2. When I mention “Terminal”, I mean ITerm2. Although the steps are the same for both Terminal or ITerm2.
对于此博客,我们将使用ITerm2。 当我提到“ Terminal”时,是指ITerm2。 尽管对于Terminal或ITerm2,步骤都相同。
第2步-将Shell更改为ZSH (Step 2— Change Shell To ZSH)
The following video shows why ZSH is better than just a bash shell.
以下视频显示了为什么ZSH比bash shell更好。
Option 1 — Use Mac’s own ZSH:
选项1-使用Mac自己的ZSH:
Mac comes with a ZSH out-of-the-box, so we don’t need to install it. However, sometimes it’s an older version of ZSH. Typically it’s located at /bin/zsh. To use it, all we need to do is to change shell (chsh).
Mac附带了开箱即用的ZSH,因此我们不需要安装它。 但是,有时它是ZSH的旧版本。 通常,它位于/ bin / zsh中。 要使用它,我们要做的就是更改shell(chsh)。
- Open the Terminal (or ITerm2) and type the following command. 打开终端(或ITerm2),然后键入以下命令。
$ chsh -s $(which zsh)
2. Enter the password and it will change the shell, upon logout and login.
2.输入密码,注销并登录后它将更改外壳。
3. Logout and re-login
3. 注销并重新登录
4. To test, open the Terminal and type the following, and it should say zsh.
4.要进行测试,请打开“终端”并键入以下内容,并显示zsh。
$ echo $0
zsh //should return zsh
Option 2— Install Homebrew and Install latest ZSH via Homebrew
选项2 —安装Homebrew并通过Homebrew安装最新的ZSH
This option is pretty common among users, because some of the plugins only work with the latest ZSH.
此选项在用户中非常常见,因为某些插件仅与最新的ZSH一起使用。
Homebrew, simply said, is a command line installer for all sorts of software. Let’s install that first.
简而言之,Homebrew是用于各种软件的命令行安装程序。 让我们先安装它。
- Install Homebrew by running the following command. 通过运行以下命令来安装Homebrew。
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2. If you get Command Line Tools for Xcode error, it means you haven’t installed the CLI tools for Xcode. If you don’t get the error, you can skip this step, because you already have it installed.
2.如果出现Xcode命令行工具错误,则表示您尚未安装Xcode的CLI工具。 如果没有收到错误,则可以跳过此步骤,因为您已经安装了它。
XCode Developer CLI tools are used by various apps that manipulate core OSX features. So make sure to install the Xcode CLI tools by running the following command.
XCode Developer CLI工具由操纵核心OSX功能的各种应用程序使用。 因此,请确保通过运行以下命令来安装Xcode CLI工具。
$ xcode-select —-install
$ xcode-select —-install
Note: The above command opens up Mac’s installer and installs the XCode Developer CLI tools. If it doesn’t work, try
xcode-select -r
to reset.注意:上面的命令将打开Mac的安装程序并安装XCode Developer CLI工具。 如果不起作用,请尝试使用
xcode-select -r
进行重置。
3. Install ZSH via Homebrew
3.通过自制软件安装ZSH
Run the following command to install ZSH. It gets installed at /usr/local/bin/zsh
PS: Mac’s default ZSH is at /bin/zsh
运行以下命令以安装ZSH。 它安装在/usr/local/bin/zsh
PS:Mac的默认ZSH在/bin/zsh
brew install zsh
4. Use the Homebrew version of ZSH
4.使用ZSH的自制版本
Run the following command. You will be prompted to enter Mac’s password.
运行以下命令。 系统将提示您输入Mac的密码。
chsh -s /usr/local/bin/zsh
5. Logout and log back in.
5.注销并重新登录。
6. Test if we are using ZSH and the correct ZSH
6.测试我们是否使用ZSH和正确的ZSH
$ echo $0
zsh //correct
$ which zsh
/usr/local/bin/zsh //correct
第3步-“哦,我的ZSH” (Step 3— “Oh My ZSH”)
“Oh My ZSH” is a plugin that runs on top of ZSH. It provides default config for ZSH (~/.zhrc file) and also provides themes and more features.
“哦,我的ZSH”是在ZSH之上运行的插件。 它提供了ZSH(〜/ .zhrc文件)的默认配置,还提供了主题和更多功能。
From what I know, most power users who use ZSH also use “Oh My ZSH”.
据我所知,大多数使用ZSH的高级用户也使用“哦,我的ZSH”。
Install “Oh My ZSH”
安装“哦,我的ZSH”
Run the following command to install “oh My ZSH”.
运行以下命令以安装“ oh My ZSH”。
sh -c "$(curl -fsSL https://raw.github.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
2. Close and quit ITerm2 and reopen it.
2.关闭并退出ITerm2,然后重新打开。
It should look something like below. Notice that the prompt has changed and the theme is a bit different — That’s “Oh My ZSH” in action for you.
它看起来应该像下面这样。 请注意,提示已更改,主题有所不同-这就是“噢,我的ZSH”为您服务。
第4步-更改主题并安装字体 (Step 4— Change Themes And Install Fonts)
In this step, we’ll add two different “Oh My ZSH” Themes. “Oh My ZSH” comes with tons of themes. PS: But some Themes need extra steps like installing specific fonts and so on.
在这一步中,我们将添加两个不同的“ Oh My ZSH”主题。 “哦,我的ZSH”带有大量主题 。 PS:但是某些主题需要额外的步骤,例如安装特定的字体等。
To set a Theme, simply open ~/.zshrc file (created by “Oh My ZSH”) and change the theme as shown below.
要设置主题,只需打开〜/ .zshrc文件(由“ Oh My ZSH”创建)并更改主题,如下所示。
PS: .zshrc is the config file for ZSH shell. People who don’t use “Oh My ZSH” will have to manually create this file and add any configs themselves. “Oh My ZSH” automatically creates this file if it doesn’t exist and then adds its own set of configs into this file.
PS:.zshrc是ZSH Shell的配置文件。 不使用“ Oh My ZSH”的用户将必须手动创建此文件并自己添加任何配置。 如果“ Oh My ZSH”不存在,它将自动创建该文件,然后将其自己的一组配置添加到该文件中。
主题1-让我们添加一个名为“ Avit”的主题 (Theme 1 — Let’s add a Theme called “Avit”)
- Open .zshrc 打开.zshrc
$ open ~/.zshrc
2. Change the Theme to “Avit”
2.将主题更改为“ Avit”
You can browse all the “Oh My ZSH” Themes here. To change the Theme, simply change the ZSH_THEME value in ~/.zshrc file from robbyrussell to Avit.
您可以在此处浏览所有“哦,我的ZSH”主题。 要更改主题,只需将〜/ .zshrc文件中的ZSH_THEME值从robbyrussell更改为Avit即可 。
3. Update ZSH config
3.更新ZSH配置
Run the following command to update the config.
运行以下命令以更新配置。
$ source ~/.zshrc
4. Change the background color and font size
4.更改背景颜色和字体大小
Open ITerm2 > Preferences > Profiles > Colors and change the background black color to use 20% gray as shown below.
打开ITerm2>首选项>配置文件>颜色,然后将背景黑色更改为20%灰色,如下所示。
Then open Text > Change Font and change the size to 14pt.
然后打开“文本”>“更改字体”,并将大小更改为14pt。
OK, Let’s install a different Theme that needs fonts.
好,让我们安装一个需要字体的主题。
主题2-安装“ agnoster”哦,我的ZSH主题 (Theme 2 — Installing “agnoster” Oh My ZSH theme)
This is a popular theme because it emulates the Powerline Python app that enhances the terminal. The following picture shows how it looks. But this theme also needs us to install Powerline themes.
这是一个受欢迎的主题,因为它模仿了增强终端功能的Powerline Python应用程序。 下图显示了外观。 但是,此主题还需要我们安装电力线主题。
1. Install Powerline fonts
1.安装电力线字体
$ git clone https://github.com/powerline/fonts.git
$ cd fonts
$ ./install.sh
2. Change the Theme to “agnoster”
2.将主题更改为“ agnoster”
$ open ~/.zshrc
Set ZSH_THEME="agnoster" and save the file
3. Quit ITerm2 and reopen it.
3.退出ITerm2并重新打开它。
4. Set Powerline font
4.设置电源线字体
You can set any Powerline patched font you like. All the fonts end with “for Powerline”.
您可以设置任何喜欢的Powerline修补字体。 所有字体都以“ for Powerline”结尾。
Open ITerm2 > Preferences > Profiles > Text > Change Font
and set it to something that has “for Powerline”. I’m choosing “Meslo LG DZ for Powerline” font.
打开ITerm2 > Preferences > Profiles > Text > Change Font
,并将其设置为具有“用于Powerline”的名称。 我选择“ Meslo LG DZ for Powerline”字体。
Note — If you are confused about the fonts and Themes: the Themes are for “Oh My ZSH” and ZSH shell and the fonts are for the Iterm2 itself.
注—如果您对字体和主题感到困惑:主题用于“哦,我的ZSH”和ZSH Shell,字体用于Iterm2本身。
5.全部完成 (5. All Done)
At this point your Terminal should look like below:
此时,您的终端应如下所示:
步骤5 —安装iTerm2“配色方案”(ITerm2主题) (Step 5 — Install iTerm2 “color schemes” (ITerm2 Themes))
There are plenty of gorgeous color schemes for iTerm2. These schemes change the foreground color, background color, cursor color, and so on. You can find them at iTerm2-color-schemes Github repo.
iTerm2有很多华丽的配色方案。 这些方案可以更改前景色,背景色,光标颜色等。 您可以在iTerm2-color-schemes Github存储库中找到它们。
Note: These are just color schemes of the ITerm2 UI and don’t deal with the command prompt’s look and feel like “Oh My ZSH”’s themes (other than just changing colors).
注意:这些只是ITerm2 UI的配色方案,并不像“ Oh My ZSH”的主题一样处理命令提示符的外观(不仅仅是更改颜色)。
Follow these steps to install them.
请按照以下步骤进行安装。
Download the iTerm2-color-schemes as a zip file and extract it
将iTerm2-color-schemes下载为zip文件并解压缩
The “Schemes” folder contains all the color scheme files — they end with
.itermcolors
“ Schemes”文件夹包含所有配色方案文件-它们以
.itermcolors
Open
iTerm2 > Preferences > Profile > Colors > Color Presets > Import
打开
iTerm2 > Preferences > Profile > Colors > Color Presets > Import
- In the import window, navigate to the “Schemes” folder (from step 2) 在导入窗口中,导航到“ Schemes”文件夹(从步骤2开始)
- Select all the files so you can import all the color schemes at once 选择所有文件,以便您可以一次导入所有配色方案
- Simply select whichever color scheme you like. 只需选择您喜欢的任何配色方案。
My favorites are Batman and Argonaut
我最喜欢的是蝙蝠侠和Argonaut
The Argonaut color scheme looks like below:
Argonaut配色方案如下所示:
第6步-安装插件 (Step 6— Install Plugins)
Plugins add more functionalities to your workflow. By default “Oh My ZSH” already has the “git” plugin! and that’s why you were able to see all those Git statuses in the prompts in earlier screenshots. Let’s add another one to see how it works.
插件为您的工作流程增加了更多功能。 默认情况下,“哦,我的ZSH”已经具有“ git”插件! 这就是为什么您能够在早期屏幕截图的提示中看到所有那些Git状态的原因。 让我们再添加一个,看看它是如何工作的。
Note: In this section, we’ll install two different plugins to show how they work.
注意:在本节中,我们将安装两个不同的插件以展示它们的工作方式。
插件1 —添加语法突出显示插件 (Plugin 1 — Add Syntax Highlighting Plugin)
The Syntax Highlighting plugin adds beautiful colors to the commands you are typing as shown below.
语法突出显示插件可为您键入的命令添加漂亮的颜色,如下所示。
- Clone the zsh-syntax-highlighting plugin’s repo and copy it to the “Oh My ZSH” plugins directory. 克隆zsh-syntax-highlighting插件的存储库,并将其复制到“ Oh My ZSH”插件目录。
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
2. Activate the plugin in ~/.zshrc
by adding `zsh-syntax-highlighting
to the Plugins section as shown below.
2.通过在插件部分中添加` zsh-syntax-highlighting
来激活~/.zshrc
中的插件,如下所示。
3. Re-read zshrc configuration
3.重新读取zshrc配置
source ~/.zshrc
插件2 —添加ZSH-AutoSuggestion插件 (Plugin 2 — Add ZSH-AutoSuggestion Plugin)
This plugin auto suggests any of the previous commands. Pretty handy! To select the completion, simply press → key.
该插件会自动建议以前的任何命令。 很方便! 要选择完成,只需按→键。
- Install the plugin 安装插件
git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions
PS: ZSH_CUSTOM points to ~/.oh-my-zsh/custom
PS:ZSH_CUSTOM指向〜/ .oh-my-zsh / custom
2. Open ~/.zshrc
and add zsh-autosuggestions
2.打开~/.zshrc
并添加zsh-autosuggestions
步骤7 —使用连字支持 (Step 7 — Use Ligature Support)
There are various fonts that help make operators like less than, double equals, right arrow, not equals, and so on look beautiful. For example, every time you type: =>, it becomes: →.
有多种字体可以使运算符看起来像小于,双等于,右箭头,非等于等。 例如,每次键入:=>,它将变为:→。
To use this, we need fonts that support ligatures. We also need to enable it in ITerm2. FiraCode is one such font. Follow the steps to install and enable ligatures.
要使用此字体,我们需要支持连字的字体。 我们还需要在ITerm2中启用它。 FiraCode就是这样一种字体。 请按照以下步骤安装和启用连字。
Download the FiraCode repo and extract the zip file (or clone it)
下载FiraCode存储库并解压缩zip文件(或克隆它)
Open the
dstr > ttf
folder and double click on all the*.ttf
files and select the “Install font” button to install each of the font variations.打开
dstr > ttf
文件夹,双击所有*.ttf
文件,然后选择“安装字体”按钮以安装每个字体变体。Navigate to
ITerm2 | Preferences | Profiles | Text
导航到
ITerm2 | Preferences | Profiles | Text
ITerm2 | Preferences | Profiles | Text
Select
Use Ligatures
checkbox选择
Use Ligatures
复选框Click on
Change Font
and selectFira Code Regular
font单击
Change Font
然后选择Fira Code Regular
字体
摘要 (Summary)
We have covered a lot in this blog starting from installing latest ZSH via Homebrew, Oh My ZSH, Plugins, Themes, enable “ligatures” for FiraCode font.
从通过Homebrew,Oh My ZSH,插件,主题安装最新的ZSH开始,为FiraCode字体启用“连字”,我们在此博客中介绍了很多内容。
?? Thank you!
?? 谢谢!
如果这有用,请单击拍手? 请点击以下几次以显示您的支持! ???? (If this was useful, please click the clap ? button down below a few times to show your support! ⬇⬇⬇ ??)
我的其他帖子 (My Other Posts)
https://medium.com/@rajaraodv/latest
https://medium.com/@rajaraodv/latest
ECMAScript 2015+ (ECMAScript 2015+)
Check out these useful ECMAScript 2015 (ES6) tips and tricks
终端改进 (Terminal Improvements)
How to Jazz Up Your Terminal — A Step By Step Guide With Pictures
万维网 (WWW)
虚拟DOM (Virtual DOM)
React表现 (React Performance)
功能编程 (Functional Programming)
Functional Programming In JS — With Practical Examples (Part 1)
Functional Programming In JS — With Practical Examples (Part 2)
Web包装 (WebPack)
Webpack & Hot Module Replacement [HMR] (under-the-hood)
Webpack和热模块更换[HMR] ( 后台 )
Draft.js (Draft.js)
React And Redux: (React And Redux :)
A Guide For Building A React Redux CRUD App (3-page app)
构建React Redux CRUD应用程序指南 (3页应用程序)
如果这有用,请单击拍手? 几次点击下面的按钮表示您的支持! ???? (If this was useful, please click the clap ? button below a few times to show your support! ⬇⬇⬇ ??)
If you have questions, please feel free to ask me on Twitter: https://twitter.com/rajaraodv
如果您有任何疑问,请随时在Twitter上问我: https : //twitter.com/rajaraodv
终端zsh