zsh 主题 自定义

tech2022-09-02  114

zsh 主题 自定义

As web developers, the command line is becoming an ever more important part of our workflow. We use it to install packages from npm, to test API endpoints, to push commits to GitHub, and lots more besides.

作为Web开发人员,命令行正在成为我们工作流程中越来越重要的部分。 我们使用它来从npm安装软件包,测试API端点,将提交推送到GitHub等。

My shell of choice is zsh. It is a highly customizable Unix shell, that packs some very powerful features such as killer tab completion, clever history, remote file expansion, and much more.

我选择的外壳是zsh 。 它是一个高度可定制的Unix shell,其中包含一些非常强大的功能,例如杀手级选项卡完成,巧妙的历史记录,远程文件扩展等等 。

In this article I’ll show you how to install zsh, then offer ten tips and tricks to make you more productive when working with it.

在本文中,我将向您展示如何安装zsh,然后提供十个技巧和窍门,使您在使用它时工作效率更高。

This is a beginner-level guide which can be followed by anybody (even Windows users, thanks to Windows Subsystem for Linux). However, in light of Apple’s announcement that zsh is now the standard shell on macOS Catalina, mac users might find it especially helpful.

这是一个入门级指南,任何人(即使Windows用户,也要感谢Linux的Windows子系统)都可以遵循。 但是,鉴于苹果公司宣布zsh现在是macOS Catalina上的标准外壳 ,mac用户可能会发现它特别有用。

Let’s get started.

让我们开始吧。

安装 (Installation)

I don’t want to offer in-depth installation instructions for each operating system, rather some general guidelines instead. If you get stuck installing zsh, there is plenty of help available online.

我不想为每个操作系统提供深入的安装说明,而是提供一些常规指导。 如果您在安装zsh时遇到问题,可以在线获得大量帮助。

At the time of writing the current zsh version is 5.7.1.

在撰写本文时,当前的zsh版本是5.7.1。

苹果系统 (macOS)

Most versions of macOS ship with zsh pre-installed. You can check if this is the case and if so, which version you are running using the command: zsh --version. If the version is 4.3.9 or higher, you should be good to go (we’ll need at least this version to install Oh My Zsh later on). If not, you can follow this guide to install a more recent version of zsh using homebrew.

大多数版本的macOS都预装了zsh。 您可以使用命令zsh --version来检查是否是这种情况,以及正在运行的是哪个版本。 如果版本为4.3.9或更高版本,那么您应该可以使用(我们至少需要此版本才能安装Oh My Zsh)。 如果没有,您可以按照本指南使用自制软件安装zsh的最新版本。

Once installed, you can set zsh as the default shell using: chsh -s $(which zsh). After issuing this command, you’ll need to log out, then log back in again for the changes to take effect.

安装后,可以使用以下命令将zsh设置为默认外壳: chsh -s $(which zsh) 。 发出此命令后,您需要注销,然后重新登录以使更改生效。

If at any point you decide you don’t like zsh, you can revert to Bash using: chsh -s $(which bash).

如果您在任何时候都不喜欢zsh,可以使用chsh -s $(which bash)还原为Bash。

的Linux (Linux)

On Ubuntu-based distros, you can install zsh using: sudo apt-get install zsh. Once the installation completes, you can check the version using zsh --version, then make zsh your default shell using chsh -s $(which zsh). You’ll need to log out, then log back in for the changes to take effect.

在基于Ubuntu的发行版上,可以使用以下sudo apt-get install zsh安装zsh: sudo apt-get install zsh 。 安装完成后,可以使用zsh --version检查版本,然后使用chsh -s $(which zsh)将zsh设置为默认外壳。 您需要注销,然后重新登录以使更改生效。

As with macOS, you can revert back to Bash using: chsh -s $(which bash).

与macOS一样,您可以使用chsh -s $(which bash)恢复到Bash。

If you are running a non-Ubuntu based distro, then check out the instructions for other distros.

如果您运行的不是基于Ubuntu的发行版,请查看有关其他发行版的说明 。

视窗 (Windows)

Unfortunately, this is where things start to get a little complicated. Zsh is a Unix shell and for it to work on Windows, you’ll need to activate Windows Subsystem for Linux (WSL), an environment in Windows 10 for running Linux binaries.

不幸的是,这里的事情开始变得有些复杂。 Zsh是Unix shell,要使其在Windows上运行,您需要激活Windows子系统Linux(WSL) ,这是Windows 10中用于运行Linux二进制文件的环境。

There are various tutorials online explaining how to get up and running with zsh in Window 10s. I found these two to be up-to-date and easy to follow:

在线上有各种教程,介绍了如何在Window 10s中使用zsh进行启动和运行。 我发现这两个是最新的,易于遵循:

How to Install and Use the Linux Bash Shell on Windows 10 – follow this one first to install WSL

如何在Windows 10上安装和使用Linux Bash Shell –首先按照此步骤安装WSL

How to Use Zsh (or Another Shell) in Windows 10 – follow this one second to install zsh

如何在Windows 10中使用Zsh(或另一个Shell) –请花一秒钟的时间安装zsh

Note that it is also possible to get zsh running with Cygwin. Here are instructions for doing that.

注意,也可以使zsh与Cygwin一起运行 。 这是执行此操作的说明 。

第一次运行 (First Run)

When you first open zsh, you’ll be greeted by the following menu.

首次打开zsh时,以下菜单将为您打招呼。

If you select (1) you’ll be taken to a menu that allows you to configure history, keybindings and a bunch of other things. However, I suggest selecting (2) which will create a configuration profile with the recommended default settings.

如果选择(1)您将进入一个菜单,该菜单可让您配置历史记录,键绑定和其他内容。 但是,我建议选择(2) ,它将使用建议的默认设置创建一个配置文件。

查找配置文件 (Locating the Configuration File)

Now let’s have a look at the file that zsh just created. Enter your home directory and open the .zshrc file in your editor of choice. This file is run whenever you start zsh and is the place where any custom configuration lives.

现在让我们看一下zsh刚刚创建的文件。 输入您的主目录,然后在您选择的编辑器中打开.zshrc文件。 每当您启动zsh时,该文件就会运行,并且是任何自定义配置所在的地方。

Note: file names that begin with a dot are hidden by default on most operating systems, so you’ll need to make it visible before you can edit it. If you’re not sure how, search for “Show hidden dot files mac/Linux etc”.

注意 :在大多数操作系统上,默认情况下,以点开头的文件名是隐藏的,因此您必须先使其可见,然后才能进行编辑。 如果不确定如何,请搜索“显示隐藏的点文件mac / Linux等”。

We can demonstrate how this file works by creating an alias. In their simplest form, aliases are terminal shortcuts for regular commands. Add the following to the bottom of .zshrc and save the file:

我们可以通过创建别名来演示此文件的工作方式。 以最简单的形式,别名是常规命令的终端快捷方式。 将以下内容添加到.zshrc的底部并保存文件:

alias myip="curl http://ipecho.net/plain; echo"

Restart your shell (for example, by closing it then opening it again), then type myip. Providing you have the cURL program installed, you should see your current public IP address output to the terminal. If you’d like to experiment more with aliases, check out 7 Super Useful Aliases to make your development life easier.

重新启动您的外壳程序(例如,通过关闭然后再次打开它),然后键入myip 。 如果已安装cURL程序 ,则应该看到当前输出到终端的公共IP地址。 如果您想对别名进行更多试验,请查看7种“超级有用的别名”,使您的开发工作更轻松 。

Shut the terminal by typing exit, then locate the .zsh_history file, which is also in your home directory. This is where zsh stores a list of your previous terminal commands. Currently it should contain two lines, namely myip and exit.

通过键入exit关闭终端,然后找到.zsh_history文件,该文件也在您的主目录中。 这是zsh存储以前的终端命令列表的地方。 当前,它应该包含两行,即myip和exit 。

Note: We’ll be reloading our shell several times through out the tutorial. You can also do this with a command: source ~/.zshrc.

注意:在整个教程中,我们将多次重新加载Shell。 您也可以使用以下命令执行此操作: source ~/.zshrc 。

检查你的进度 (Check Your Progress)

By this point you should have zsh installed and set as your default shell. If you experience any problems, try creating a topic on SitePoint’s forums and ask for help there.

至此,您应该已经安装了zsh并将其设置为默认外壳程序。 如果您遇到任何问题,请尝试在SitePoint的论坛上创建主题, 然后在此处寻求帮助。

Now let’s get into some tips.

现在让我们开始一些技巧。

1.安装Oh My Zsh (1. Install Oh My Zsh)

If you only follow one of these tips, it needs to be this one.

如果您仅遵循这些提示之一,则必须是这一提示。

Oh My Zsh is a community-driven framework for managing your zsh configuration and comes bundled with thousands of helpful functions, helpers, plugins and themes. Many of the following tips will rely on you having this installed.

噢,我的Zsh是一个社区驱动的框架,用于管理您的zsh配置,并捆绑了成千上万的有用功能,帮助程序,插件和主题。 以下许多技巧将取决于您是否安装了此技巧。

As is explained on the project’s homepage, you can install it using cURL or wget.

如项目首页所述,您可以使用cURL或wget进行安装。

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

This assumes you have git installed, which you hopefully do already. If not, you can grab it from the project’s homepage.

这假设您已经安装了git,希望您已经这样做了。 如果没有,您可以从项目的主页上获取它 。

As you can see, from the post installation message, Oh My Zsh created a backup of your .zshrc file, then replaced it with its own version. This means that you’ll need to copy over any custom configuration (such as our myip alias) to your new .zshrc file.

如您所见,在安装后消息中,“噢,我的Zsh”创建了.zshrc文件的备份,然后将其替换为自己的版本。 这意味着您需要将任何自定义配置(例如我们的myip别名)复制到新的.zshrc文件中。

2.选择一个主题 (2. Select a Theme)

If you spend a lot of time in the terminal, it’s worth investing some effort in making it visually appealing. Luckily Oh My Zsh ships with a whole bunch of themes.

如果您在终端上花费大量时间,则值得投入一些精力使其外观更具吸引力。 幸运的是,我的Zsh附带了很多主题 。

If you look in the ~/.zshrc file for the ZSH_THEME variable, you’ll find it’s set to robbyrussel. This is the default theme that the creator of Oh My Zsh uses.

如果在~/.zshrc ZSH_THEME文件中查找ZSH_THEME变量,则会发现它设置为robbyrussel 。 这是Oh My Zsh的创建者使用的默认主题。

To install a different theme, pick one from the link above and change the value of the ZSH_THEME variable, before restarting your shell. For example, setting ZSH_THEME="avit" will cause Oh My Zsh to use the avit theme.

要安装其他主题,请在重新启动外壳程序之前,从上面的链接中选择一个并更改ZSH_THEME变量的值。 例如,设置ZSH_THEME="avit"将导致Oh My Zsh使用avit主题 。

You might also like to alter the color scheme for your terminal. On my Linux machine, I could do this via Edit > Preferences > Colors. Removing the tick from Use colors from system theme, then selecting Solarized dark as a scheme, gives me a very appealing result in next to no time.

您可能还想更改终端的配色方案。 在我的Linux机器上,我可以通过编辑 > 首选项 > 颜色来执行此操作。 从系统主题的“使用颜色”中删除勾号,然后选择“ 变暗的黑色”作为方案,几乎没有时间可以给我一个非常吸引人的结果。

Notice how the theme recognizes that it’s in a git repo, tells me which branch I’m on and displays a green tick to let me know that everything is up to date.

注意主题如何识别它在git repo中,告诉我我在哪个分支上,并显示一个绿色的勾号,让我知道一切都是最新的。

I encourage you to have a look through the available themes and find one that suits you.

我鼓励您浏览可用的主题并找到适合您的主题。

故障排除 (Troubleshooting)

When I was testing this on WSL, I was seeing broken characters in my terminal, as soon as I installed Oh My Zsh. To remedy this I had to install the Powerline fonts and tell my terminal to use them.

当我在WSL上进行测试时,安装了Oh My Zsh后,我在终端中看到了残破的字符。 为了解决这个问题,我必须安装Powerline字体,并告诉终端使用它们。

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

Then open an admin PowerShell, navigate to the root of the repo and run:

然后打开一个管理PowerShell,导航到存储库的根目录并运行:

.\install.ps1

If PowerShell blocks you from running the script, then try setting the ExecutionPolicy as per this StackOverflow answer. Once the fonts are installed, be sure to set it back again.

如果PowerShell阻止您运行脚本,请尝试按照此StackOverflow答案设置ExecutionPolicy 。 安装字体后,请确保再次将其重新设置。

Finally, right click on the terminal’s title bar, choose Properties > Font and make sure a Powerline font is selected. In testing, Deja Vu Sans Mono for Powerline worked well for me.

最后,右键单击终端的标题栏,选择“ 属性” >“ 字体” ,并确保选择了Powerline字体。 在测试中, Powerline的Deja Vu Sans Mono对我来说效果很好。

Also note that a couple of the themes require Powerline fonts, regardless of the operating system. We’ll look at installing one of these themes (Agnoster) towards the end of the article.

还请注意,与操作系统无关,有两个主题需要Powerline字体。 我们将在文章结尾处安装这些主题之一( Agnoster )。

3.处理历史 (3. Working with History)

One of my favorite Oh My Zsh features is the way that it lets you search through your history. Imagine that the contents of .zsh_history look like this:

我最喜欢的“我的Zsh”功能之一是它可以让您搜索历史记录的方式。 假设.zsh_history的内容如下所示:

cd Desktop mkdir my-project cd my-project npm init -y mkdir {src,build} touch index.js

If you are in the terminal and press the ↑ key, you would expect to cycle through each of those history entries one by one, right? No surprise there.

如果您在终端中并按↑键,则希望一个个地循环浏览这些历史记录条目,对吗? 毫不奇怪。

However, Oh My Zsh allows you to enter the beginning of a command, then press the ↑ key to cycle through matching entries. So, in the above example if you entered “mkdir” and then pressed the ↑ key, you would see “mkdir {src,build}” displayed. If you pressed it again, you would then see “mkdir my-project”.

但是,哦,我的Zsh允许您输入命令的开头,然后按↑键在匹配的条目之间循环。 因此,在上面的示例中,如果您输入“ mkdir”,然后按↑键,则将看到显示“ mkdir {src,build}”。 如果再次按下它,您将看到“ mkdir my-project”。

I use this feature all the time. For instance, when I want to ssh into a server and can’t remember the exact credentials, I just enter “ssh” and can cycle through recent connections until I find the right one. Or, when I can’t remember the exact syntax of a command, I can just enter the first few characters and cycle through any matches.

我一直在使用此功能。 例如,当我想通过SSH进入服务器并且不记得确切的凭据时,我只需输入“ ssh”即可循环浏览最近的连接,直到找到正确的凭据为止。 或者,当我不记得命令的确切语法时,我只需输入前几个字符并循环进行任何匹配即可。

4.自动建议FTW! (4. Autosuggestions FTW!)

Another great feature of Oh My Zsh is plugins. These add new features to your shell and augment its functionality.

Oh My Zsh的另一个重要功能是插件 。 这些为您的外壳添加了新功能并增强了其功能。

Oh My Zsh ships with hundreds of plugins for every conceivable use and we’ll look at some of these later in the article. In this section however, I’d like to introduce you to a third party plugin called autosuggestions. This suggests commands as you type based on history.

噢,我的Zsh附带了数百种可用于各种用途的插件 ,我们将在本文后面介绍其中的一些插件 。 但是,在本部分中,我想向您介绍一个名为autosuggestions的第三方插件。 这会建议您根据历史记录键入命令。

To install, you need to clone its repository into $ZSH_CUSTOM/plugins. By default this is ~/.oh-my-zsh/custom/plugins.

要安装,您需要将其存储库克隆到$ZSH_CUSTOM/plugins 。 默认情况下,这是~/.oh-my-zsh/custom/plugins 。

git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

Once done, to activate it, hop into the ~/.zshrc file and uncomment the following line:

完成后,要激活它,请~/.zshrc文件,并取消注释以下行:

# plugins=(git)

Then replace git with zsh-autosuggestions

然后用zsh-autosuggestions替换git

plugins=(zsh-autosuggestions)

Restart your shell and you will notice that as you type a command, Oh My Zsh will make suggestions based on your history. If the suggestion is the one you are looking for, press the → key to accept it. A real time saver!

重新启动外壳程序,您会发现在键入命令时,“噢,我的Zsh”会根据您的历史记录提出建议。 如果建议是您要寻找的建议,请按→键接受。 实时节省!

5.使用Oh My Zsh进行文件导航 (5. File Navigation with Oh My Zsh)

Another awesome thing about Oh My Zsh, is how easy it makes it to navigate around your machine.

关于“ Oh My Zsh”的另一项令人敬畏的事情是,它使导航计算机的过程变得如此容易。

For example, when you want to change directory, it is not necessary to enter the cd command, i.e. cd Desktop just becomes Desktop. And that works with paths, too — you can enter /home/jim/Desktop and end up right where you wanted to go.

例如,当您要更改目录时,无需输入cd命令,即cd Desktop变为Desktop 。 这也适用于路径-您可以输入/home/jim/Desktop并最终到达您想去的地方。

Oh My Zsh has great autocomplete, too. Once you have started typing a path, you can press TAB to have it expand a list of all possible folders you can navigate to. If you continue tabbing, you can move through this list until you select a folder by pressing Return. Pressing TAB again after that will restart the process.

哦,我的Zsh也具有出色的自动填充功能。 开始输入路径后,可以按TAB键使其展开所有可以浏览到的文件夹的列表。 如果继续进行制表,则可以在此列表中移动,直到通过按Return键选择一个文件夹。 之后再次按TAB键将重新启动该过程。

Finally, it’s worth mentioning that Oh My Zsh provides a number of commands and aliases for working with, and navigating directories. For example, typing ... will move you up two directories and typing take <dir-name> will create a new directory and navigate to it. Oh My Zsh also supports dynamic path completion, so typing (for example) /h/j/De and pressing Tab will expand the path to /home/jim/Desktop. Cool, eh?

最后,值得一提的是,“噢,我的Zsh”提供了许多用于处理目录和浏览目录的命令和别名 。 例如,键入...将使您上移两个目录,键入take <dir-name>将创建一个新目录并导航至该目录。 噢,我的Zsh还支持动态路径完成,因此,键入(例如) /h/j/De并按Tab可以将路径扩展到/home/jim/Desktop 。 酷吧?

Bonus Tip: If you’re feeling lazy, you can just drag and drop a folder onto the terminal window and the path will be expanded for you.

温馨提示 :如果您感到懒惰,只需将文件夹拖放到终端窗口,即可为您扩展路径。

6.使用z导航到任何内容 (6. Navigate to Anything Using z)

z is a handy plugin that builds a list of your most frequent and recent folders (it calls these “frecent”) and allows you to jump to them with one command. This is often much more convenient than having to tab through a nested folder structure.

z是一个方便的插件 ,可构建您最常用和最近的文件夹的列表(它称为“最新”),并允许您使用一个命令跳转到它们。 这通常比必须通过嵌套的文件夹结构来制表更为方便。

To install the plugin, all you have to do is add it to your .zshrc file like so:

要安装插件,只需将其添加到.zshrc文件中,如下所示:

plugins=(z zsh-autosuggestions)

Then restart your terminal.

然后重新启动您的终端。

Once installed, z will have a short learning phase as it observes you navigating around your PC with the terminal. After a while however, you will be able to type z followed by any word that is in your desired directory path. The plugin will use fuzzy matching to figure out which folder you want to go to and expand the path accordingly. If there is more than one possibility you can tab through the options as described in the previous tip.

安装后,z会带您进入一个简短的学习阶段,因为它将观察到您使用终端在PC上浏览。 但是,过一会儿,您将能够键入z后跟所需目录路径中的任何单词。 该插件将使用模糊匹配来找出您要转到哪个文件夹,并相应地扩展路径。 如果存在多种可能性,则可以按上一个技巧中的说明选择选项。

This might not sound like a big deal, but you’ll be able to open a shell, type z my-project and have it expand the path to /home/jim/files/some/deeply/nested/directory/or/other/my-project. Then when you’re in that directory, you can type z my-other-project and have it expand the path to /var/www/html/projects/top/secret/my-other.project.

这听起来似乎没什么大不了,但是您可以打开一个shell,输入z my-project并将其扩展到/home/jim/files/some/deeply/nested/directory/or/other/my-project的路径/home/jim/files/some/deeply/nested/directory/or/other/my-project 。 然后,当您在该目录中时,可以输入z my-other-project并将其扩展到/var/www/html/projects/top/secret/my-other.project的路径。

Note: the first time I ran z, and attempted to change directory, I got the error_z_dirs:2: no such file or directory: /home/jim/.z. This was a one off, as z apparently needed to make a .z file in my home directory. If you run into any problems, this article has some suggestions.

注意:第一次运行z并尝试更改目录时,出现错误_z_dirs:2: no such file or directory: /home/jim/.z 。 这是一个问题,因为z显然需要在我的主目录中创建一个.z文件。 如果遇到任何问题, 本文将提供一些建议 。

7.使用git (7. Working with git)

Zsh includes some basic git integration out of the box. For example, if you type git and press the Tab key, zsh will helpfully spit out a long list of possible git commands. This becomes slightly more useful if you type git, followed by the first couple of letters of the command you are looking for. For example git a + Tab produces:

Zsh包含一些基本的git集成。 例如,如果键入git并按Tab键,则zsh将有助于吐出一长串可能的git命令。 如果键入git ,然后键入要查找的命令的前几个字母,这将变得更加有用。 例如git a + Tab产生:

add -- add file contents to index am -- apply patches from a mailbox apply -- apply patch to files and/or to index archimport -- import an Arch repository into git archive -- create archive of files from named tree

Things start to get more interesting when you install the Oh My Zsh git plugin.

当您安装Oh My Zsh git插件时,事情开始变得越来越有趣。

plugins=(git z zsh-autosuggestions)

This provides a whole bunch of aliases, as well as some useful functions for working with git. Some of the ones I use frequently are:

这提供了一堆别名,以及一些使用git的有用功能。 我经常使用的一些是:

gaa – git add all

gaa – git add all

gdca – git diff --cached

gdca – git diff --cached gdca

gp – git push

gp – git push

gpf! – git push --force

gpf! – git push --force

grhh – git reset --hard

grhh – git reset --hard grhh

gst – git status

gst – git status

You could also create an alias for several commands at once, by adding the following to your .zshrc file:

通过将以下内容添加到.zshrc文件中,您还可以一次为多个命令创建别名:

function acp() { git add . git commit -m "$1" git push }

Now, when you’re in a git repo, typing acp "a commit message" will add all changed files, commit them with whatever commit message you specified, then push them to your remote. Credit for this idea goes to Ali Spittel.

现在,当您在git repo中时,键入acp "a commit message"将添加所有更改的文件,使用您指定的任何提交消息将它们提交,然后将它们推送到远程。 这个想法归功于Ali Spittel 。

8.获得有关git仓库状态的即时反馈 (8. Get Instant Feedback on the State of a git Repo)

At the top of the article we activated a theme called avit. When in a git repo, this theme will display the branch name, as well as a cross or tick indicating whether everything branch is up-to-date. I love being able to see this information at a glance and it is definitely a big step up from having to type git status all the time.

在本文的顶部,我们激活了一个名为avit的主题。 在git repo中时,此主题将显示分支名称,以及叉号或勾号,指示是否所有分支都是最新的。 我喜欢能够一目了然地看到这些信息,这绝对是必须一直输入git status一大进步。

There are a couple of themes, however, that display this information in a more intuitive way. My favorite is Agnoster. Let’s install that now.

但是,有两个主题以更直观的方式显示此信息。 我最喜欢的是Agnoster 。 让我们现在安装它。

For Agnoster to render arrows and git icons correctly, you will likely need to install a Powerline-patched font. WSL users can do this by following the instructions in the troubleshooting section above. For Mac and Linux users, installation instructions can be found in the project’s repo.

为了使Agnoster正确呈现箭头和git图标,您可能需要安装Powerline修补字体 。 WSL用户可以按照上面的疑难解答部分中的说明进行操作。 对于Mac和Linux用户, 可以在项目的repo中找到安装说明 。

Mac users on High Sierra or later may need to perform some additional work to get these fonts to display. Unless you are on Catalina, this method is recommended. Catalina users will need to install a patched font and select it in their terminal settings.

使用High Sierra或更高版本的Mac用户可能需要执行一些其他工作才能显示这些字体。 除非您在Catalina上,否则建议使用此方法 。 Catalina用户将需要安装修补字体并在其终端设置中选择它。

To test if your terminal can display all of the necessary characters. run the following command:

测试您的终端是否可以显示所有必要的字符。 运行以下命令:

echo "\ue0b0 \u00b1 \ue0a0 \u27a6 \u2718 \u26a1 \u2699"

The result should look like this:

结果应如下所示:

After that, enable the theme by changing the following line in your .zshrc file:

之后,通过更改.zshrc文件中的以下行来启用主题:

ZSH_THEME="agnoster"

and restarting the terminal. Once Agnoster is up and running, you’ll have a more intuitive view of the status of any git repository. You’ll also receive visual feedback as to whether the previous command succeeded or failed, and whether you are working with elevated privileges.

然后重新启动终端。 一旦Agnoster启动并运行,您将可以更直观地查看任何git存储库的状态。 您还将收到有关上一个命令是成功还是失败以及您是否正在使用特权提升的视觉反馈。

Tip If you don’t like the user@host part of the prompt, you can make this disappear by adding DEFAULT_USER=your_user_name to the .zshrc file.

提示如果您不喜欢提示的user@host部分,可以通过将DEFAULT_USER=your_user_name添加到.zshrc文件中来使其消失。

9.插件,插件,插件 (9. Plugins, Plugins, Plugins)

As mentioned, Oh My Zsh ships with a lot of plugins. You really should look through these and invest some time learning those that will help your workflow. To get you started, here are some popular ones to be aware of:

如前所述, 哦,我的Zsh附带了许多插件 。 您确实应该仔细阅读这些内容,并花一些时间学习那些对您的工作流程有帮助的内容。 为了让您起步,以下是一些需要注意的热门事项:

cloudapp – uploads files and piped contents to the Cloudapp service. Outputs and copies the resultant URL to the clipboard.

cloudapp –将文件和管道内容上传到Cloudapp服务。 输出结果URL并将其复制到剪贴板。

command-not-found – if a command is not recognized in the $PATH, this will use Ubuntu’s command-not-found package to find it or suggest spelling mistakes (Only for Ubuntu and openSUSE).

command-not-found –如果$PATH未识别命令,它将使用Ubuntu的command-not-found包查找该命令或建议拼写错误(仅适用于Ubuntu和openSUSE)。

node – open the Node API, for your current version, in your browser.

节点 –在浏览器中打开当前版本的Node API。

npm – adds autocompletion to npm.

npm –将自动补全添加到npm。

sudo – hitting ESC twice puts sudo in front of the current command, or the last one if the command line is empty.

sudo –两次按ESC键会将sudo置于当前命令的前面;如果命令行为空,则将最后一个放在前面。

vscode – makes interaction between the command line and the code editor easier.

vscode –使命令行和代码编辑器之间的交互更加容易。

10.关键组合 (10. Key Combos)

This is not a zsh specific tip, but to wrap up I wanted to make you aware of these five time-saving key combos.

这不是zsh特有的技巧,但总的来说,我想让您了解这五个省时的键组合。

Ctrl + U – delete from the cursor to the start of the line.

Ctrl + U –从光标删除到行的开头。

Ctrl + K – delete from the cursor to the end of the line.

Ctrl + K –从光标删除到行尾。

Ctrl + W – delete from the cursor to the start of the preceding word.

Ctrl + W –从光标删除到上一个单词的开头。

Alt + D – delete from the cursor to the end of the next word.

Alt + D –从光标删除到下一个单词的末尾。

Ctrl + L – clear the terminal.

Ctrl + L –清除终端。

If you can memorize those, you’ll be surprised at how often they come in handy.

如果您能记住这些,您会惊讶于它们派上用场的频率。

结论 (Conclusion)

In this post I have demonstrated how to install zsh and set it as your default shell. I have also showed how to get the most out of your new terminal with the Oh My Zsh framework. It’s my hope that if you give these a try for a couple of weeks, you’ll wonder how you ever did without.

在这篇文章中,我演示了如何安装zsh并将其设置为默认外壳。 我还展示了如何使用Oh My Zsh框架充分利用您的新终端。 我希望,如果您尝试几个星期,您将不知如何做到。

And don’t forget, if you have any problems with any of this, you can hop over to SitePoint forums and ask for help there. I’d also be happy to hear if I missed anything out — for example, your favorite theme, plugin, alias, or productivity tip.

并且不要忘记,如果您对此有任何疑问,可以跳到SitePoint论坛并在此处寻求帮助。 我也很高兴听到我是否错过了任何内容,例如您最喜欢的主题,插件,别名或工作效率提示。

You can hit me up either on the forums or on Twitter.

您可以在论坛或Twitter上打我。

翻译自: https://www.sitepoint.com/zsh-tips-tricks/

zsh 主题 自定义

相关资源:ohmyzsh-theme:oh-my-zsh的主题,灵感来自其他主题-源码
最新回复(0)