macos终端美化_关于macOS终端美化的最轻松的指南Z Shell中的速成课程

macos终端美化

Speeding it up more than the standard bash terminal that comes with your MacOS by using iTerm2, Z shell, Oh My Zsh along with the Powerlevel10k theme and Neofetch to make your terminal look like this:

通过使用iTerm2,Z shell,Oh My Zsh以及Powerlevel10k主题和Neofetch,使其比MacOS随附的标准bash终端更快,从而使终端看起来像这样:

NOTE : This tutorial will use iterm2 which is a popular alternative to the MacOS terminal. If you want you can use other terminals, usually Alacritty is a good option and looks damn cool too. This guide will also cover some simple things you can do with the Z-shell to show you why it is so much better than the bash shell. If you get stuck somewhere, don’t worry and keep reading I’ve tried to cover all the problems I ran into myself and how I went back. The reason I decided to write this article, even though some similar articles exist out there, is that personally I’ve run into problems and bugs at many points trying out themes and thus to make others lives easier, I made this comprehensive hackle-free guide to getting a fast and good looking terminal.

注意:本教程将使用iterm2,它是MacOS终端的流行替代品。 如果您希望可以使用其他终端,通常Alacritty是一个不错的选择,而且看起来也很酷。 本指南还将介绍您可以使用Z-shell进行的一些简单操作,向您展示为什么它比bash外壳好得多。 如果您被卡在某个地方,请不要担心,继续阅读我会尽力解决我遇到的所有问题以及我如何回去。 我决定写这篇文章的原因是,尽管那里有一些类似的文章,但我个人还是在尝试主题的许多时候遇到了问题和错误,从而使其他人的生活变得更加轻松,我使这一全面的工作变得无忧无虑。快速而美观的终端指南。

步骤1:如果尚未下载Homebrew,请下载。 (Step 1 : Download Homebrew if you already haven’t.)

Homebrew is the best thing to happen to the MacOS and honestly it makes developers' lives easy every day. If you’re not aware of this novel software, learn how to use it! At some point, it will be useful to you because of how easily you can download packages and maintain them with it, Without needing to know the git and ruby code underneath. You can get homebrew here, Just run this code in your terminal and answer install prompts:

自制软件是MacOS上发生的最好的事情,老实说,它使开发人员的生活每天都变得轻松。 如果您不了解此新颖软件,请学习如何使用它! 在某些时候,这对您很有用,因为您可以轻松下载软件包并使用它们进行维护,而无需了解下面的git和ruby代码。 您可以在此处进行自制程序,只需在终端中运行以下代码并回答安装提示:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"

步骤2:使用Homebrew命令下载iTerm2 (Step 2 : Download iTerm2 using Homebrew commands)

Why iTerm2? For the simple reason that it is way more customisable than the Mac terminal, you can adjust transparency, add images to the background, download and use themes for iTerm2, use custom fonts and a lot more:

为什么选择iTerm2? 出于简单的原因,它比Mac终端更具可定制性,因此您可以调整透明度,将图像添加到背景,下载和使用iTerm2主题,使用自定义字体等等:

brew cask install iterm2

NOTE : If you want to see how to use custom themes and fonts follow this section or else feel free to skip to step 3.

注意:如果要查看如何使用自定义主题和字体,请遵循本节,否则请跳至步骤3。

  1. To open Preferences (Settings for iTerm2 basically) use COMMAND+i. A window will pop up where you can play around with colours and fonts, whatever works for you. I’m currently using the custom theme called dark+ with foreground text set to green. You can get all the themes here :

    要打开首选项(基本上是iTerm2的设置),请使用COMMAND + i。 会弹出一个窗口,您可以在其中随意使用颜色和字体。 我当前正在使用名为dark +的自定义主题,前景文本设置为绿色。 您可以在这里获得所有主题:

Select the theme you would like to download the code as an .itermcolors file then go to preferences on iterm2 and select color presets. Import the file from where you saved it and select it. Don’t forget to save your settings by selecting “Copy current settings to default profile” in General.

选择您想要将代码下载为.itermcolors文件的主题,然后转到iterm2的首选项并选择颜色预设。 从保存文件的位置导入文件并选择它。 不要忘记在常规中选择“将当前设置复制到默认配置文件”来保存设置。

2. I’m also using a downloaded custom font called Inconsolata dz, which is a powerline font, (you maybe asked to download this by Powerlevel10k but it's not compulsory and I’ll show you why later). However, if you want to download it:

2.我还使用了一种名为Inconsolata dz的下载自定义字体,它是电力线字体(您可能会被Powerlevel10k要求下载该字体,但这不是强制性的,稍后我将向您展示为什么)。 但是,如果要下载它:

# clone the repo of powerline fonts
git clone https://github.com/powerline/fonts.git --depth=1
# install
cd fonts
./install.sh
# clean-up a bit, remove the file after installation.
cd ..
rm -rf fonts# If you want to uninstall Powerline fonts completely for some #reason :./uninstall.sh

After doing this the fonts should appear in Text > Fonts > Dropdown Menu.

完成此操作后,字体应显示在“文本”>“字体”>“下拉菜单”中。

步骤3:打开iTerm2并安装zsh和ohmyzsh (Step 3 : Open iTerm2 and install zsh and ohmyzsh)

Zsh is a fast alternative to bash commands with the advantage that you can club your repetitive bash commands into a single zsh alias. It is very customisable, you can use custom themes, apps, and plugins with zsh. However, zsh alone is incomplete and requires a powerful plugin manager like ohmyzsh which we will be installing as well. I will also cover some simple things you can do with Z-Shell and OhMyZsh.

Zsh是bash命令的快速替代方法,其优点是您可以将重复的bash命令组合为一个zsh别名。 这是非常可定制的,您可以在zsh中使用自定义主题,应用程序和插件。 但是,仅zsh尚不完善,需要像ohmyzsh这样功能强大的插件管理器,我们也将安装它。 我还将介绍Z-Shell和OhMyZsh可以完成的一些简单操作。

brew install zsh

Then paste and execute this in your terminal for Oh My Zsh:

然后将其粘贴并在您的终端中执行Oh My Zsh:

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

步骤4:了解如何围绕Z-Shell进行工作 (Step 4 : Learning how to work your way around Z-Shell)

(If you do not care about this you may skip) Now that you have Z-shell and Oh My Zsh installed, somethings you Should know before we download the Powerlevel10k theme and Neofetch to further beautify our terminal are these: Managing Themes, Managing Plugins, Adding a permanent alias ( think of this as the custom commands) and finally getting your pip and conda commands to work with Zsh because they don’t do so by default.

(如果您不关心此问题,则可以跳过)现在已经安装了Z-shell和Oh My Zsh,在下载Powerlevel10k主题和Neofetch以进一步美化我们的终端之前,您应该了解以下内容:管理主题,管理插件,添加一个永久别名(将其视为自定义命令),并最终使pip和conda命令与Zsh一起使用,因为默认情况下它们不这样做。

  1. Managing themes: Say you’ve downloaded a custom theme and applied it to the terminal (Which we will soon), However ensuring that the theme loads every time, on startup is another issue altogether. To do this we will:

    管理主题:假设您已经下载了一个自定义主题,并将其应用到了终端(稍后将进行介绍),但是,确保每次启动时都加载该主题是另一个问题。 为此,我们将:
open ~/.zshrc

Think of this file as the code that executes every time you start your Z-shell. Head over to the part that says ZSH_THEME and edit its value. the default should be “robbyrussell” you can make it “agnoster” or a custom theme after we download it. But DON’T close the File just yet :)

将此文件视为每次启动Z-shell时执行的代码。 转至显示ZSH_THEME的部分,然后编辑其值。 默认值为“ robbyrussell”,您可以在下载后将其设置为“ agnoster”或自定义主题。 但是暂时不要关闭文件:)

2. Managing Plugins : In the same File zshrc go to the section that says plugins = (git) and edit it to plugins = (git docker). This will add docker as a plugin to the Z-shell. To know more about what plugins to use for your convenience head over to this link, however fair warning: Using too many plugins will slow you terminal startup considerably. Again don’t close the file after you’re done.

2.管理插件:在同一文件zshrc中,转到显示plugins =(git)的部分,然后将其编辑为plugins =(git docker)。 这会将docker作为插件添加到Z-shell。 要了解有关为方便起见使用哪些插件的更多信息,请转至此链接,但是警告是:使用太多的插件会大大降低终端的启动速度。 同样,完成后不要关闭文件。

3. Now I had run into an issue way later that screwed up everything for me, i.e, I couldn’t run conda or pip on my Z-shell. So I’m giving you guys the fix to this early on itself. Just like ~/.zshrc our bash shell has a file that allows us to use conda commands, we will simply call the file in our zshrc file. So open the zshrc file and at the end of it copy this code:

3.现在我遇到了一个麻烦的问题,那就是为我搞砸了所有东西,即我无法在Z-shell上运行conda或pip。 因此,我正在尽早给大家解决此问题的方法。 就像〜/ .zshrc一样,我们的bash shell具有一个允许使用conda命令的文件,我们只需在zshrc文件中调用该文件即可。 因此,打开zshrc文件,并在其末尾复制以下代码:

source ~/.bash_profile

4. We will see how to use custom commands as permanent aliases in this section. I hope you have your ~/.zshrc open, if not open it using the command in step 1 (you may also use vim “vi” or “nano” just anything that edits text). Head over the part that says “Example aliases” right at the end of the file and makes an alias. The format is simple alias <name> = “<bash command>”

4.我们将在本节中了解如何将自定义命令用作永久别名。 我希望您打开〜/ .zshrc,如果没有使用步骤1中的命令将其打开(您也可以使用vim“ vi”或“ nano”编辑任何文本)。 转至文件末尾的“示例别名”部分,并创建一个别名。 格式为简单别名<名称> =“ <bash命令>”

# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"# Alias to run docker
alias dk="docker ps"#Alias to show lyrics of current song (Needs swaglyrics installed)
alias showlyrics="swaglyrics -c"

Now you can run dk and it will run docker ps or showlyrics to print lyrics of the spotify song playing (again, needs swaglyrics installed-just an example)

现在您可以运行dk,它将运行docker ps或showlyrics来打印Spotify歌曲播放的歌词(同样,需要安装swaglyrics-仅作为示例)

5. Now that you’re done with all the edits to the ~/.zshrc file hit Command+S to save it and head over to your iTerm2 to run this code and apply all the changes, alternatively you can restart the terminal and changes will apply automatically:

5.现在,您已经完成对〜/ .zshrc文件的所有编辑,请按Command + S保存并转到iTerm2来运行此代码并应用所有更改,或者您可以重新启动终端并进行更改将自动应用:

source ~/.zshrc

6. The last thing we will see is how to run bash commands in zsh, or chnage shells completely. Also if you screw up in the installation stage just run the command to uninstall ohmyzsh, it’s gonna be like a rest and you can start again. To run bash in Z-shell use the command:

6.我们将看到的最后一件事是如何在zsh或完全chnage shell中运行bash命令。 另外,如果您在安装阶段搞砸了,只需运行命令以卸载ohmyzsh,就好比休息了,您可以重新开始。 要在Z-shell中运行bash,请使用以下命令:

exec bash #executes bash shell

To change default shell completely (requires password and to restart terminal for changes to take place):

要完全更改默认外壳程序(需要密码并重新启动终端以进行更改):

chsh -s /bin/bash #zsh to bash
chsh -s /bin/zsh #bash to zsh

To uninstall oh my zsh and reset shell to bash to start over, simply run:

要卸载我的zsh并将shell重置为bash以重新开始,只需运行:

uninstall_oh_my_zsh #in the zsh shell#if this doesn't work remove the .ohmyzsh file from the root #directory itself before re-intsalling zshsudo rm -R "yourRootPath/.ohmyzsh"## if you screw up so bad you need to install zsh again:brew reinstall zsh

步骤5:更多自定义! (Step 5 : More Customisation !)

In this section, we will install Powerlevel10k, which is one of the fastest themes for the Z-shell and use Neofetch along with it which displays the PC details and distribution as shown in the image. Note that if you just came for neofetch (a lot of people do), you can also use neofetch with your bash shell, I will show you how. But using Zsh is a lot faster and easier once you start using the terminal a lot more.

在本部分中,我们将安装Powerlevel10k,它是Z-shell最快的主题之一,并与它一起使用Neofetch,它显示了PC的详细信息和分布,如图所示。 请注意,如果您只是来进行neofetch(很多人这样做),也可以将neofetch与bash shell一起使用,我将向您展示如何使用。 但是,一旦您开始更多地使用终端,使用Zsh就会更快,更容易。

功率水平10k (Powerlevel10k)

To clone your custom theme from its github repository into the /.ohmyzsh ’s custom themes directory run the following code in your terminal :

要将自定义主题从其github存储库克隆到/.ohmyzsh的自定义主题目录,请在终端中运行以下代码:

git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/themes/powerlevel10k

After that’s done hopefully the theme has been downloaded into the directory. Now all you need to do is open the ~/.zshrc file and set the theme so that it opens as required (shown in step 4.1)

希望完成后,主题已下载到目录中。 现在,您需要做的就是打开〜/ .zshrc文件并设置主题,使其根据需要打开(如步骤4.1所示)。

open ~/. zshrc## Head over to ZSH_THEME in zshrc and paste this line instead:ZSH_THEME="powerlevel10k/powerlevel10k"##Save and run in terminal using source or restart.

When you open the terminal, Powerlevel10k’s built in installation guide will start. It may prompt you to download the Meslo Font (a powerline font), It’s not compulsory to do so. The rest of the steps are pretty self explanatory, just select the designs you like. The reason we were prompted to install powerline fonts (already shown in step 2.2) is because it supports powerline glyphs that make your shell look cool. However iTerm2 has it’s own built in powerline glyphs feature that you can enable in Text > Use built-in Powerline Glyphs, that is, if you did not download the fonts in step 2.2, which is fine.

当您打开终端时,Powerlevel10k的内置安装指南将启动。 它可能会提示您下载Meslo字体(电力线字体),这不是强制性的。 其余步骤很容易解释,只需选择所需的设计即可。 提示我们安装电源线字体的原因(已在步骤2.2中显示)是因为它支持使您的外壳看起来很酷的电源线字形。 但是,iTerm2具有它自己的内置电力线字形功能,可以在“文本”>“使用内置电力线字形”中启用该功能,也就是说,如果您没有在步骤2.2中下载字体,那很好。

After you’re done with the installation guide make sure to add this code in ~/.zshrc so that the setup guide doesn’t start everytime you start the iTerm2. If this was automatically added during the installation guide itself you may skip the step, so it’s worth checking in ~/.zshrc

在完成安装指南后,请确保将此代码添加到〜/ .zshrc中,以使安装指南不会在每次启动iTerm2时启动。 如果这是在安装指南本身中自动添加的,则可以跳过此步骤,因此值得在〜/ .zshrc中进行检查。

#open ~/.zshrc and head over to the end of the file to add:#to disable Powerline prompt
POWERLEVEL9K_DISABLE_CONFIGURATION_WIZARD=true#To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh#save and source ~/.zshrc in the terminal to save settings.

The setup for other custom themes are also fairly similar.

其他自定义主题的设置也非常相似。

Neofetch (Neofetch)

Neofetch is a command-line system information tool written in bash 3.2+. Neofetch displays information about your operating system, software and hardware in an aesthetic and visually pleasing way.

Neofetch是用bash 3.2+编写的命令行系统信息工具。 Neofetch以美观和美观的方式显示有关您的操作系统,软件和硬件的信息。

To install neofetch just simply run:

要安装neofetch,只需运行:

brew install neofetch ##if this does not work :
#1. Clone the repo
git clone https://github.com/dylanaraps/neofetch
#2. go to the directory
cd neofetch
#3. install using make command
make install##Or you can try pip install (if you followed step 4.3)

Now that this is done, you can just run the command “neofetch” in the terminal to display your Mac details along with the logo (which is also customisable). Again we need to save this in the ~/.zshrc file to make neofetch run everytime the Z-shell starts. This is simple as you just need to add neofetch to the end of ~/.zshrc and save the file, then use “source ~/.zshrc” command in the terminal to save settings.

既然完成了,您只需在终端中运行命令“ neofetch”即可显示Mac详细信息以及徽标(也可以自定义)。 同样,我们需要将其保存在〜/ .zshrc文件中,以便每次Z-shell启动时都能运行neofetch。 这很简单,因为您只需要在〜/ .zshrc的末尾添加neofetch并保存文件,然后在终端中使用“ source〜/ .zshrc”命令保存设置即可。

If you want to run neofetch with your bash shell as well:

如果您还想使用bash shell运行neofetch:

open ~/.bash_profile##Go to the end of the file and add the neofetch command
neofetch##save and exit the text editor and enter into the terminal:
source ~/.bash_profile

NOTE : Since in this tutorial we are already running ~/. bash_profile in our ~/.zshrc, this may cause neofetch to run twice, it’s upto you to figure out which shell to use.

注意:由于在本教程中,我们已经在运行〜/。 我们的〜/ .zshrc中的bash_profile,这可能会导致neofetch运行两次,这取决于您确定要使用哪个shell。

Here’s the link to neofetch’s github repo if you want to play around some more and get some customisations to amp up your terminal’s looks (for expample adding a custom logo or image instead of the ASCII apple logo):

如果您想玩得更多,并获得一些自定义来增强终端的外观,这是neofetch的github存储库的链接(例如,添加自定义徽标或图像而不是ASCII苹果徽标):

You’re all set, happy hacking!

一切就绪,黑客入侵愉快!

翻译自: https://medium.com/unknownimous/the-most-hackle-free-guide-to-terminal-beautification-for-macos-a-crash-course-in-z-shell-6e57ab17ad5e

macos终端美化

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值