什么是ZSH,为什么要用它代替Bash?

ZSH, also called the Z shell, is an extended version of the Bourne Shell (sh), with plenty of new features, and support for plugins and themes. Since it’s based on the same shell as Bash, ZSH has many of the same features, and switching over is a breeze.

ZSH也称为Z Shell,是Bourne Shell(sh)的扩展版本,具有许多新功能,并支持插件和主题。 由于ZSH与Bash基于相同的外壳,因此ZSH具有许多相同的功能,并且切换起来非常容易。

那为什么要使用它呢? (So Why Use It?)

ZSH has too many features to list here, some just minor improvements to Bash, but here are some of the major ones:

ZSH有太多功能要在这里列出,对Bash进行了一些小的改进,但是其中一些主要功能是:

  • Automatic cd: Just type the name of the directory

    自动cd:只需输入目录名称

  • Recursive path expansion: For example “/u/lo/b” expands to “/usr/local/bin”

    递归路径扩展:例如,“ / u / lo / b”扩展为“ / usr / local / bin”

  • Spelling correction and approximate completion: If you make a minor mistake typing a directory name, ZSH will fix it for you

    拼写更正和大致完成:如果您在输入目录名称时犯了一个小错误,ZSH会为您修复它

  • Plugin and theme support: ZSH includes many different plugin frameworks

    插件和主题支持: ZSH包含许多不同的插件框架

Plugin and theme support is probably the coolest feature of ZSH and is what we’ll focus on here.

插件和主题支持可能是ZSH的最酷功能,这就是我们将在此处重点介绍的功能。

安装ZSH (Installing ZSH)

If you’re on macOS and have Homebrew installed (which you should), you can install ZSH with a single command:

如果您使用的是macOS,并且已安装Homebrew (应该这样做),则可以使用单个命令安装ZSH:

brew install zsh

Also for macOS users, you should probably use iTerm instead of the native terminal, as it has much better color support (plus a lot of other features).

同样对于macOS用户,您可能应该使用iTerm而不是本机终端,因为它具有更好的颜色支持(以及许多其他功能)。

If you’re on Linux, the commands can vary by the distro, but it should be a default package in your package manager. You can consult this guide if you’re having trouble.

如果您使用的是Linux,则命令可能因发行版而异,但它应该是程序包管理器中的默认程序包。 如果遇到问题,可以查阅本指南

If you’re on Windows, you may not even have Bash in the first place. You can follow this guide to set that up and enable ZSH.

如果您使用的是Windows,则可能甚至没有Bash。 您可以按照本指南进行设置并启用ZSH。

安装Oh-My-Zsh (Installing Oh-My-Zsh)

()

Oh-My-Zsh is the most popular plugin framework for ZSH, and it comes with many built-in plugins and themes as well. There are also a couple of other plugin frameworks, including Antigen, which is a full package manager for ZSH, but Oh-My-Zsh has loads of plugins built right in and does its job well.

Oh-My-Zsh是ZSH最受欢迎的插件框架,它还带有许多内置插件和主题。 还有其他两个插件框架,包括Antigen ,它是ZSH的完整软件包管理器,但是Oh-My-Zsh内置了许多插件,并且可以很好地完成工作。

Oh-My-Zsh has a simple install script you can run:

Oh-My-Zsh有一个可以运行的简单安装脚本:

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

From there, you can enable and disable plugins by adding them to your .zshrc file, located in your ~ directory.

从那里,您可以通过将插件添加到〜目录中的.zshrc文件中来启用和禁用插件。

You can get a full list of plugins on the Oh-My-Zsh repository.

您可以在Oh-My-Zsh存储库中获得完整的插件列表。

主题 (Themes)

There are plenty of themes to go around, but powerlevel9k is by far the coolest. It adds a right-aligned info box, integration with git and command history, incredible customization, and wraps it all up in a slick interface based on the powerline plugin for vim.

有很多主题可以讨论,但是powerlevel9k到目前为止是最酷的。 它添加了一个右对齐的信息框,与git和命令历史记录集成,令人难以置信的自定义,并将其全部包装在基于vim的电力线插件的漂亮界面中。

You’ll want to use iTerm on macOS, or any terminal with 24-bit color, to get the most out of powerlevel9k (or any ZSH theme, really).

您可能要在macOS或任何24位彩色的终端上使用iTerm,以充分利用powerlevel9k(或任何ZSH主题)。

To set up powerlevel9k (if you installed Oh-My-Zsh) just clone the repository into the .oh-my-zsh custom themes folder:

要设置powerlevel9k(如果已安装Oh-My-Zsh),只需将存储库克隆到.oh-my-zsh自定义主题文件夹中:

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

Then you need to enable it in .zshrc:

然后,您需要在.zshrc中启用它:

ZSH_THEME="powerlevel9k/powerlevel9k"

After that, source your .zshrc, and you should see the changes applied.

之后,获取您的.zshrc,然后您应该会看到所做的更改。

If you want, you can customize the default prompt by defining POWERLEVEL9K_LEFT_PROMPT_ELEMENTS in your .zshrc. Here’s mine, with a minimal prompt:

如果需要,可以通过在.zshrc中定义POWERLEVEL9K_LEFT_PROMPT_ELEMENTS来自定义默认提示。 这是我的,提示很少:

POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(vcs dir rbenv)
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(root_indicator background_jobs status load)

You can find the full documentation for powerlevel9k on the repo.

您可以在存储库中找到有关powerlevel9k的完整文档

翻译自: https://www.howtogeek.com/362409/what-is-zsh-and-why-should-you-use-it-instead-of-bash/

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值