macos zsh_如何像Pro一样使用Zsh配置macOs终端

macos zsh

by Chiamaka Ikeanyi

由池中千嘉(Chiamaka Ikeanyi)

Sometimes, using the default terminal sucks. You want to go out of the ordinary, to add life to the boring terminal and improve your productivity.

有时,使用默认终端很烂。 您想与众不同,为无聊的终端增加生活并提高生产率。

Z shell (Zsh) is a Unix shell built on top of bash (the default shell for macOS) with a large number of improvements.

Z shell (Zsh)是基于bash(macOS的默认shell)构建的Unix shell,具有许多改进。

In this walk-through, we will configure iTerm2 with ZSH and its dependencies. This is a no-brainer, and after this, you’ll ponder the reason for not discovering ZSH earlier. Well, since you’re here already, let’s kick-start this.

在本演练中,我们将使用ZSH及其依赖项配置iTerm2。 这是不费吹灰之力的,之后,您将思考不及早发现ZSH的原因。 好吧,既然您已经在这里,就让我们开始吧。

主题演讲 (Keynotes)

  • Homebrew installation

    自制安装
  • iTerm2 installation

    iTerm2安装
  • ZSH and Oh My ZSH installations

    ZSH和哦,我的ZSH安装
  • Setting up the dependencies to create a beautiful terminal

    设置依赖项以创建漂亮的终端

步骤1:安装自制软件 (Step 1: Install Homebrew)

Homebrew is a free and open-source software package management system that simplifies the installation of software on Apple’s macOS.

Homebrew是一个免费的开源软件包管理系统,可简化Apple macOS上软件的安装。

Before installing Homebrew, we need to install the CLI tools for Xcode. Open your terminal and run the command:

在安装Homebrew之前,我们需要安装Xcode的CLI工具。 打开您的终端并运行命令:

xcode-select —-install

If you get an error, run xcode-select -r to reset xcode-select.

如果出现错误,请运行xcode-select -r重置xcode-select

Then, install Homebrew.

然后,安装Homebrew。

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

步骤2:安装iTerm2 (Step 2: Install iTerm2)

iTerm2 is a replacement for terminal and the successor to iTerm. Most software engineers prefer iTerm2 over the default terminal that ships with macOS as a result of its cool features. You can integrate zsh into iTerm2 to increase productivity.

iTerm2是终端的替代品,也是iTerm的后继产品。 由于其出色的功能,大多数软件工程师更喜欢i Term2而不是macOS附带的默认终端。 您可以将zsh集成到iTerm2中以提高生产率。

To install iTerm2, run the command:

要安装iTerm2,请运行以下命令:

brew cask install iterm2

步骤3:安装ZSH (Step 3: Install ZSH)

Zsh is a shell designed for interactive use, although it is also a powerful scripting language.

Zsh是一种设计用于交互式使用的外壳程序,尽管它也是一种功能强大的脚本语言。

By default, macOs ships with zsh located in/bin/zsh.

默认情况下,macOs随附/bin/zsh

Let’s install zsh using brew and make iTerm2 use it.

让我们使用brew安装zsh,并让iTerm2使用它。

brew install zsh

步骤4:安装Oh My Zsh (Step 4: Install Oh My Zsh)

“Oh My Zsh is an open source, community-driven framework for managing your zsh configuration. It will not make you a 10x developer…but you might feel like one”

“哦,我的Zsh是用于管理zsh配置的开源,社区驱动的框架。 它不会使您成为10倍的开发人员……但您可能会觉得自己像一个人”

— Robby Russell
—罗比·罗素

It runs on Zsh to provide cool features configurable within the ~/.zhrc config file. Install Oh My Zsh by running the command

它在Zsh上运行,以提供可在〜/ .zhrc配置文件中配置的出色功能。 通过运行命令安装Oh My Zsh

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

Check the installed version

检查安装的版本

zsh --version

You can upgrade it to get the latest features it offers.

您可以对其进行升级以获得其提供的最新功能。

upgrade_oh_my_zsh

Restart iTerm2 to dive into the new experience of using Zsh. Welcome to the “Oh My Zsh” world ?.

重新启动iTerm2,以深入了解使用Zsh的新体验。 欢迎来到“噢,我的Zsh”世界?

That’s not all. Now, we will install the dependencies to get the best out of Zsh.

那不是全部。 现在,我们将安装依赖项以充分利用Zsh。

步骤5:更改默认主题 (Step 5: Change the Default Theme)

Oh My Zsh comes bundled with a lot of themes. The default theme is robbyrussell, but you can change it to any theme of your choice. In this scenario, I changed it to agnoster, an already pre-installed theme.

哦,我的Zsh捆绑了很多主题。 默认主题是robbyrussell,但是您可以将其更改为您选择的任何主题。 在这种情况下,我将其更改为已经预安装的主题agnoster。

You then need to select this theme in your ~/.zshrc. To open the config file (.zshrc), run the command:

然后,您需要在~/.zshrc选择此主题。 要打开配置文件(.zshrc),请运行以下命令:

nano ~/.zshrc

Or open the file in a text editor with

或使用以下方法在文本编辑器中打开文件:

open ~/.zshrc

Set the zsh theme and update your changes

设置zsh主题并更新您的更改

source ~/.zhrc

使用自定义主题 (Using a Custom Theme)

To install another theme not pre-installed, clone the repository into custom/themesdirectory. In this scenario, we’ll install powerlevel9k,

要安装另一个未预先安装的主题,请将存储库克隆到custom/themes目录中。 在这种情况下,我们将安装powerlevel9k

$ git clone https://github.com/bhilburn/powerlevel9k.git ~/.oh-my-zsh/custom/themes/powerlevel9k

Then, select this theme in your ~/.zshrc

然后,在~/.zshrc选择该主题

ZSH_THEME="powerlevel9k/powerlevel9k"

Update your changes by running the command source ~/.zshrc

通过运行命令source ~/.zshrc更新您的更改

Navigate to iTerm2 > Preferences > Profiles > Colors if you wish to change the background color of the terminal.

如果要更改终端的背景色,请导航至iTerm2 > Preferences > Profiles > Colors

The selected theme in this scenario requires powerline fonts. So, let’s install that.

在这种情况下,所选主题需要电力线字体。 因此,让我们安装它。

步骤6:安装字体 (Step 6: Install Fonts)

I will be using Inconsolata. Get your preferred font out of these powerline fonts. Then, download and install it.

我将使用Inconsolata 。 从这些电力线字体中获取首选字体 。 然后,下载并安装它。

Or download the entire font.

或下载整个字体。

git clone https://github.com/powerline/fonts.git

cd fonts

./install.sh

To change the font, navigate to iTerm2 > Preferences > Profiles > Text > Change Font.

要更改字体,请导航至iTerm2 > Preferences > Profiles > Text > Change Font

Now, you can see Inconsolata listed as one of the fonts. Select your preferred font. For fonts that support ligatures like FiraCode, check the “Use ligatures” option to view your arrows and other operators in a stylish manner like ( ).

现在,您可以看到Inconsolata被列为字体之一。 选择您喜欢的字体。 对于支持连字的字体(例如FiraCode) ,请选中“使用连字”选项,以类似( )的时尚方式查看箭头和其他运算符。

步骤7:安装配色方案 (Step 7: Install Color Scheme)

Let’s change the color scheme to bring out the beauty of our terminal. Navigate to iTerm2-Color-Schemes and download the ZIP folder. Then, extract the downloaded folder cos what we need resides in the schemes folder.

让我们更改配色方案,以彰显终端的美感。 导航到iTerm2-Color-Schemes并下载ZIP文件夹。 然后,解压缩下载的文件夹cos,我们需要的文件驻留在schemes文件夹中。

Navigate to iTerm2 > Preferences > Profile > Colors > Color Presets > Import

导航到iTerm2 > Preferences > Profile > Colors > Color Presets > Import

  • Navigate to the schemes folder and select your preferred color schemes to import them.

    导航到schemes文件夹,然后选择要导入的首选配色方案。
  • Click on a specific color scheme to activate it. In this scenario, I activated Batman which is my preferred color scheme.

    单击特定的配色方案将其激活。 在这种情况下,我激活了蝙蝠侠,这是我的首选配色方案。

Tada! ? We’re done with the basic settings.

多田 ? 基本设置已完成。

步骤8:安装插件 (Step 8: Install Plugins)

Oh My ZSH comes preloaded with a git plugin. To add more, for instance, docker, auto-suggestion, syntax highlighting and more:

哦,我的ZSH预装了git插件。 要添加更多内容,例如docker,自动建议,语法突出显示等:

  • Clone the Git repository

    克隆Git存储库
git clone https://github.com/zsh-users/zsh-docker.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-docker
  • Head over to .oh-my-zsh > custom > plugins directory to view the cloned directory. To access this, run the command open ~/.oh-my-zsh

    转到.oh-my-zsh > custom > plugins目录以查看克隆的目录。 要访问此文件,请运行命令open ~/.oh-my-zsh

  • Add the plugin to the plugin section of the config file ~/.zshrc shown below

    将插件添加到配置文件~/.zshrc的插件部分,如下所示

  • Update your changes by running the command source ~/.zshrc

    通过运行命令source ~/.zshrc更新您的更改

步骤9:添加别名 (Step 9: Add Aliases)

Aliases are shortcuts used to reduce the time spent on typing commands. Add aliases to commands you run in the section shown below.

别名是用于减少键入命令所花费时间的快捷方式。 在下面显示的部分中为您运行的命令添加别名。

Thanks for reading.

感谢您的阅读

If you know about other means of improving productivity using ZSH, you can drop them on the comment section, I will be glad to hear from you.

如果您知道使用ZSH提高生产率的其他方法,可以将其放在评论部分,我们将很高兴收到您的来信。

翻译自: https://www.freecodecamp.org/news/how-to-configure-your-macos-terminal-with-zsh-like-a-pro-c0ab3f3c1156/

macos zsh

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值