终端打开后-bash_如何爵士化Bash终端-带有图片的分步指南

胡志
2023-12-01

终端打开后-bash

by rajaraodv

通过rajaraodv

In this blog I’ll go over the steps to add Themes, Powerline, fonts, and powerline-gitstatus to make your regular Bash Terminal look beautiful and useful as shown in the picture above.

在此博客中,我将介绍添加主题,电源线,字体和电源线-gitstatus的步骤,以使您的常规Bash Terminal看起来美观且有用,如上图所示。

It turns out, if you are using Mac, you’ll need to jump through a lot of hoops to get this working as many instructions are for linux, or are out of date. So I thought I'd blog about it - hopefully it'll help you.

事实证明,如果您使用的是Mac,则需要跳很多步才能使它正常工作,因为许多指令是针对Linux的,或者已经过时。 所以我以为我会写博客-希望它能对您有所帮助。

Notes:

笔记:

Notes:

笔记:

1. Follow the steps carefully as any mistake will cause a lot of headaches.

1.认真执行以下步骤,因为任何错误都会引起很多头痛。

1. Follow the steps carefully as any mistake will cause a lot of headaches.

1.认真执行以下步骤,因为任何错误都会引起很多头痛。

2. This is for MacOS and for regular bash in the Terminal.app. I’m not using ZSH or Hyper in this blog — I plan to write different blogs for them.

2.这适用于MacOS和Terminal.app中的常规bash。 我不在此博客中使用ZSH或Hyper-我计划为他们编写不同的博客。

2. This is for MacOS and for regular bash in the Terminal.app. I’m not using ZSH or Hyper in this blog — I plan to write different blogs for them.

2.这适用于MacOS和Terminal.app中的常规bash。 我不在此博客中使用ZSH或Hyper-我计划为他们编写不同的博客。

OK, by default, when you have a new mac, your Terminal.app will look something like below. Let’s go ahead and add Themes, fonts, and so on.

好的,默认情况下,当您有新的Mac时,Terminal.app将如下所示。 让我们继续添加主题,字体等。

第1步-添加新主题 (Step 1 — Add A New Theme)

The first obvious step is to enhance the Theme. Terminal doesn’t provide all the cool and fancy themes that you see other developers use. Let’s download a Theme and add it to the Terminal.

显而易见的第一步是增强主题。 终端无法提供您看到其他开发人员使用的所有酷炫主题。 让我们下载一个主题并将其添加到终端中。

In this blog, I’ll add Solarized-Dark theme to our Terminal.

在此博客中,我将向我们的终端添加Solarized-Dark主题。

Note: You can download various Themes (.terminal files) from this git repo. Simply open the *.terminal file to install it, i.e. right-click on the *.terminal file > “open with" > Terminal

注意:您可以从此git repo下载各种主题(.terminal文件)。 只需打开*.terminal文件以进行安装,即right-click on the *.terminal file > “open with" > Te终端”

  1. Go to http://ethanschoonover.com/solarized

    前往http://ethanschoonover.com/solarized

  2. Scroll down and download the Theme (solarized.zip)

    向下滚动并下载主题(solarized.zip)
  3. Extract the solarized.zip file

    提取solarized.zip文件
  4. Open the osx-terminal.app-colors-solarized folder. This folder contains Theme for the terminal.

    打开osx-terminal.app-colors-solarized文件夹。 该文件夹包含终端的主题。

  5. Double click “Solarized Dark ansi.terminal” fileThis is the specific Theme file for Terminal.app. Note: If you get a warning that this is from an unidentified developer, Right-click on the file and select “Open with” > Terminal option.

    双击“ Solarized Dark ansi.terminal”文件-这是Terminal.app的特定主题文件。 注意:如果收到来自未知开发人员的警告,请右键单击该文件,然后选择“打开方式”>“终端 ”。

  6. At this point, you have the Theme installed into your Terminal. We just need to make it a default Theme.

    此时,您已将主题安装到终端中。 我们只需要使其成为默认主题即可。
  7. Open Terminal > Preferences > Text and select the “Solarized Dark …” theme and click on “Default”.

    打开终端>首选项>文本,然后选择“ Solarized Dark…”主题,然后单击“ Default”。

From now on, your Terminal should like below.

从现在开始,您的终端应如下所示。

步骤2 —安装电力线 (Step 2 — Install Powerline)

Powerline is a Python app and is a status line plugin for vim, and provides status lines and prompts for several other applications, including zsh, bash, tmux, IPython, Awesome and Qtile.

Powerline是一个Python应用程序,并且是vim的状态行插件,并为其他几个应用程序提供状态行和提示,包括zsh,bash,tmux,IPython,Awesome和Qtile。

It makes the Terminal prompt look like below.

它使终端提示如下所示。

2.1安装Python (2.1 Install Python)

Because Powerline is a Python app, we need to have Python and that too a proper version of Python.

因为Powerline是一个Python应用程序,所以我们需要拥有Python以及适当的Python版本。

  • MacOS comes with Python installed already. Ensure Python’s version is 2.7.x by typing python -V in the Terminal.

    MacOS已经安装了Python。 通过在终端中键入 python -V 来确保Python的版本为2.7.x。

  • If it’s not 2.7, install Homebrew that allows us to install various software from the CLI, by running:/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

    如果不是2.7,请通过运行以下命令来安装Homebrew ,它允许我们从CLI安装各种软件: /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

  • Run brew install python to install the latest Python via Homebrew

    运行brew install python通过Homebrew安装最新的Python

2.2 Install pip — Python的软件包管理器(类似于npm) (2.2 Install pip — A package manager for Python (similar to npm))

Install pip by running the following command

通过运行以下命令来安装pip

$ sudo easy_install pip

$ sudo easy_install pip

2.3安装XCode Developer CLI工具 (2.3 Install XCode Developer CLI tools)

XCode Developer CLI tools are used by Powerline and other apps that manipulate core OSX features. So make sure to install the XCode CLI tools by running the following command.

Powerline和其他操纵OSX核心功能的应用程序使用XCode Developer CLI工具。 因此,请确保通过运行以下命令来安装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进行重置。

2.4安装电力线 (2.4 Install Powerline)

Finally, install the Powerline (stable version) via pip by running the following command.

最后,通过运行以下命令,通过pip安装Powerline(稳定版)。

$ pip install --user powerline-status

If you want to install the latest development branch, then use:

如果要安装最新的开发分支,请使用:

$ pip install --user git+git://github.com/powerline/powerline  //dev

2.5将Powerline守护程序添加到bash (2.5 Add the Powerline daemon to bash)

We now need to add the Powerline daemon to bash so that it can monitor the Terminal prompt and make changes.

现在,我们需要将Powerline守护程序添加到bash中,以便它可以监视终端提示并进行更改。

2.5.1 Copy the Powerline’s installation location

2.5.1复制电力线的安装位置

You can figure out the location of Powerline by running the following: pip show powerline-status Copy the value from the Location field.

您可以通过运行以下命令确定pip show powerline-status的位置: pip show powerline-status从“ Location字段复制值。

2.5.2 Add the daemon with a proper location to .bash_profile

2.5.2将具有正确位置的守护程序添加到.bash_profile

  1. Make sure you have .bash_profile file in your root directory. If not following create one by doing: cd ~ && touch ~/.bash_profile

    确保您的根目录中有.bash_profile文件。 如果不遵循,则执行以下操作来创建一个: cd ~ && touch ~/.bash_profile

2. Open .bash_profile and add the following:

2.打开.bash_profile并添加以下内容:

export PATH=$PATH:$HOME/Library/Python/2.7/bin
powerline-daemon -q
POWERLINE_BASH_CONTINUATION=1
POWERLINE_BASH_SELECT=1
. /Users/rupa/Library/Python/2.7/lib/python/site-packages/powerline/bindings/bash/powerline.sh

Note: The location /Users/rupa/Library/Python/2.7/lib/python/site-packages/ is from the previous step (2.5.1). Change it to match your computer’s location.

注意:位置/Users/rupa/Library/Python/2.7/lib/python/site-packages/来自上一步(2.5.1)。 更改它以匹配您计算机的位置。

2.5.3. Restart the Terminal

2.5.3。 重新启动终端

Completely quit the Terminal if it’s open (Terminal > Quit Terminal). And open it again.

如果终端打开,请完全退出终端(终端>退出终端)。 并再次打开它。

You should be able to simply use $ source ~/.bash_profile to update the settings. But I got some odd powerline-config file is missing! Typically you get this error if you don’t have $HOME/Library/Python/2.7/bin in your PATH.

您应该可以简单地使用$ source ~/.bash_profile来更新设置。 但是我缺少一些奇怪的powerline-config文件! 通常,如果您的PATH中没有$ HOME / Library / Python / 2.7 / bin,则会出现此错误。

2.5.4 Your new Terminal

2.5.4您的新终端

Your new Terminal should look like below. It should be using “Solarized Dark ansi” theme and should show Powerline in the command prompt. But also notice that there are “?” characters! This is because Powerline uses various icons and fonts that are not available by default. So we need to install the fonts.

您的新终端应如下所示。 它应使用“ Solarized Dark ansi”主题,并在命令提示符下显示Powerline。 但也请注意,这里有“?” 人物! 这是因为Powerline使用默认情况下不可用的各种图标和字体。 因此,我们需要安装字体。

步骤3 —安装电力线字体 (Step 3 — Install Powerline fonts)

To install Powerline fonts, simply go to https://github.com/powerline/fonts. There you’ll see a whole bunch of folders. Each one is a font, aka “Patched fonts”.

要安装Powerline字体,只需转到https://github.com/powerline/fonts 。 在那里,您会看到一堆文件夹。 每个字体都是一种字体,也称为“修补字体”。

It is called “Patched fonts” because people have taken regular fonts and have added/patched additional Powerline specific icons and fonts to them.
之所以称其为“修补字体”,是因为人们采用了常规字体,并为其添加/修补了其他特定于Powerline的图标和字体。

3.1下载整个仓库并解压缩 (3.1 Download the whole repo and unzip it)

  • Click on the “Clone or download” button and download the whole repo so you try various fonts.

    单击“克隆或下载”按钮,然后下载整个存储库,以便尝试各种字体。
  • Unzip the fonts-master.zip

    解压缩fonts-master.zip

3.2安装一些字体 (3.2 Install some fonts)

Let’s open Meslo dotted fonts folder. It will look like below. You’ll see a whole bunch of .ttf file. Each one of them is a font but some are “bold” version of the font, some are “regular” version and so on.

打开Meslo点划线字体 夹。 如下图所示。 您会看到一大堆.ttf文件。 每个字体都是一种字体,但有些是字体的“粗体”版本,有些是“常规”版本,依此类推。

Simply double-click on the .ttf file and press “Install font” to install the font on your computer.

只需双击.ttf文件,然后按“安装字体”即可在计算机上安装字体。

For our case, let’s install “Meslo LG L DZ Regular for Powerline.ttf” and “Meslo LG L DZ Italic for Powerline.ttf”. This will add a regular and an Italic version of the Meslo font.

对于我们的情况,让我们安装“ Powerline.ttf的Meslo LG L DZ Regular”和“ Powerline.ttf的Meslo LG L DZ Italic”。 这将添加Meslo字体的常规斜体版本。

3.3在终端主题中选择字体 (3.3 Select the font in the Terminal’s Theme)

Remember we added “Solarized Dark” theme in Step 1? That didn’t have any fonts in it and MacOS had some default font. All we need to do is to set our Meslo dotted font for this theme and we are done!

还记得我们在步骤1中添加了“ Solarized Dark”主题吗? 那没有任何字体,MacOS有一些默认字体。 我们需要做的就是为此主题设置Meslo点缀字体,我们完成了!

  1. Open Terminal > Preferences > Text

    打开终端>首选项>文本
  2. Select Solarized Dark ansi Theme

    选择日光化深色ansi主题

  3. Click on the “Font” button — This opens up “Fonts” dialog

    单击“字体”按钮-这将打开“字体”对话框
  4. In the “Fonts” dialog, select “Meslo LG L DZ for Powerline” in the Family and also select font size 14 (so it’s easier to read).

    在“字体”对话框中,选择“系列”中的“ Meslo LG L DZ for Powerline”,然后选择字体大小14(这样更易于阅读)。

3.4重启终端 (3.4 Restart Terminal)

Completely quit the Terminal (Terminal > Quit Terminal) and then reopen it.

完全退出终端(终端>退出终端),然后重新打开。

步骤4 —将Git信息添加到提示 (Step 4 — Adding Git information to the prompt)

In order to display various Git status at the prompt, we need to install powerline-gitstatus. It is a simple add-on to Powerline and adds multiple colors and Themes to display various git status information.

为了在提示符下显示各种Git状态,我们需要安装powerline-gitstatus 。 它是Powerline的一个简单附件,添加了多种颜色和主题以显示各种git状态信息。

4.1安装powerline-gitstatus (4.1 Install powerline-gitstatus)

pip install --user powerline-gitstatus
Note: “ — user” command is required to install it in the user’s profile.
注意:需要“ —用户”命令才能将其安装在用户的配置文件中。

4.2向Powerline添加powerline-gitstatus配色方案 (4.2 Add powerline-gitstatus color schemes to Powerline)

4.2.1 Open the following colorschemes/shell/default.json folder

4.2.1打开以下colorschemes/shell/default.json文件夹

${powerline-install-directory}/powerline/config_files/colorschemes/shell/default.json

//For example:
/Users/rupa/Library/Python/2.7/lib/python/site-packages/powerline/config_files/colorschemes/shell/default.json

4.2.2 Add the following colors:

4.2.2添加以下颜色:

As mentioned in the powerline-gitstatus readme. PS: Just copy the colors inside “groups” and then append it to the default.json as shown below.

如powerline-gitstatus 自述文件中所述 。 PS:只需复制“组”内的颜色,然后将其添加到default.json,如下所示。

Here is my color schemes default.json (you may copy and paste this instead):

这是我的配色方案default.json(您可以复制并粘贴它):

{
	"name": "Default color scheme for shell prompts",
	"groups": {
		"hostname": {
			"fg": "brightyellow",
			"bg": "mediumorange",
			"attrs": []
		},
		"environment": {
			"fg": "white",
			"bg": "darkestgreen",
			"attrs": []
		},
		"mode": {
			"fg": "darkestgreen",
			"bg": "brightgreen",
			"attrs": ["bold"]
		},
		"attached_clients": {
			"fg": "white",
			"bg": "darkestgreen",
			"attrs": []
		},

		"gitstatus": {
			"fg": "gray8",
			"bg": "gray2",
			"attrs": []
		},
		"gitstatus_branch": {
			"fg": "gray8",
			"bg": "gray2",
			"attrs": []
		},
		"gitstatus_branch_clean": {
			"fg": "green",
			"bg": "gray2",
			"attrs": []
		},
		"gitstatus_branch_dirty": {
			"fg": "gray8",
			"bg": "gray2",
			"attrs": []
		},
		"gitstatus_branch_detached": {
			"fg": "mediumpurple",
			"bg": "gray2",
			"attrs": []
		},
		"gitstatus_tag": {
			"fg": "darkcyan",
			"bg": "gray2",
			"attrs": []
		},
		"gitstatus_behind": {
			"fg": "gray10",
			"bg": "gray2",
			"attrs": []
		},
		"gitstatus_ahead": {
			"fg": "gray10",
			"bg": "gray2",
			"attrs": []
		},
		"gitstatus_staged": {
			"fg": "green",
			"bg": "gray2",
			"attrs": []
		},
		"gitstatus_unmerged": {
			"fg": "brightred",
			"bg": "gray2",
			"attrs": []
		},
		"gitstatus_changed": {
			"fg": "mediumorange",
			"bg": "gray2",
			"attrs": []
		},
		"gitstatus_untracked": {
			"fg": "brightestorange",
			"bg": "gray2",
			"attrs": []
		},
		"gitstatus_stashed": {
			"fg": "darkblue",
			"bg": "gray2",
			"attrs": []
		},
		"gitstatus:divider": {
			"fg": "gray8",
			"bg": "gray2",
			"attrs": []
		}
	},
	"mode_translations": {
		"vicmd": {
			"groups": {
				"mode": {
					"fg": "darkestcyan",
					"bg": "white",
					"attrs": ["bold"]
				}
			}
		}
	}
}

4.3激活主题 (4.3 Activate The Theme)

4.3.1 Open Theme’s default.json file

4.3.1打开主题的default.json文件

${powerline-install-directory}/powerline/config_files/themes/shell/default.json

//For example:
/Users/rupa/Library/Python/2.7/lib/python/site-packages/powerline/config_files/themes/shell/default.json

4.3.2 Add the following to the default.json

4.3.2将以下内容添加到default.json

{
    "function": "powerline_gitstatus.gitstatus",
    "priority": 40
}

Below is my Powerline’s Theme default.json(you may copy and paste this instead):

下面是我的电力线主题default.json(您可以复制并粘贴该主题):

Note: I have removed everything from the “right” section and also removed “job number” (“jobnum”) to keep things clean. Otherwise, you’ll see a little artifact on the right-hand side edge of the prompt.
注意:我从“右侧”部分中删除了所有内容,还删除了“作业号”(“ jobnum”)以保持环境清洁。 否则,您会在提示的右侧边缘看到一些小瑕疵。
{
	"segments": {
		"left": [{
				"function": "powerline.segments.shell.mode"
			},
			{
				"function": "powerline.segments.common.net.hostname",
				"priority": 10
			},
			{
				"function": "powerline.segments.common.env.user",
				"priority": 30
			},
			{
				"function": "powerline.segments.shell.cwd",
				"priority": 10
			}, {
				"function": "powerline_gitstatus.gitstatus",
				"priority": 40
			}
		],
		"right": []
	}
}

4.4重新启动守护程序 (4.4 Restart the Daemon)

Save the file and run the following: powerline-daemon —-replace in the Terminal.

保存文件并运行以下命令: powerline-daemon —-replace 在终端中 powerline-daemon —-replace

Important Note: Every time you make changes to Powerline’s config, in addition to restarting the Terminal, you’ll also need to restart the daemon to see the changes reflected by running: powerline-daemon —-replace.

重要说明:每次更改Powerline的配置时,除了重新启动Terminal之外,还需要重新启动 守护程序以查看运行所反映的更改powerline-daemon —-replace

4.5重启终端 (4.5 Restart The Terminal)

Quit the Terminal (Terminal > Quit Terminal) and open it again.

退出终端(终端>退出终端),然后再次打开。

At this point, we are all done! whew! If you open the Terminal, and navigate to any git repo, and play around, it should look like the following.

至此,我们都完成了! ! 如果您打开终端,并导航至任何git repo,然后进行播放,则其外观应如下所示。

Here is how it looks in Solarized-Light Theme:

这是Solarized-Light主题的外观:

Here is how it looks in Cobalt2 Theme:

这是Cobalt2主题的外观:

?? Thank you!

?? 谢谢!

If you have questions, please feel free to ask me on Twitter: https://twitter.com/rajaraodv

如果您有任何疑问,请随时在Twitter上问我: https : //twitter.com/rajaraodv

如果这有用,请单击拍手? 请点击以下几次以显示您的支持! ???? (If this was useful, please click the clap ? button down below a few times to show your support! ⬇⬇⬇ ??)

https://medium.com/@rajaraodv/latest

https://medium.com/@rajaraodv/latest

ECMAScript 2015+ (ECMAScript 2015+)

  1. Check out these useful ECMAScript 2015 (ES6) tips and tricks

    查看这些有用的ECMAScript 2015(ES6)提示和技巧

  2. 5 JavaScript “Bad” Parts That Are Fixed In ES6

    ES6中修复的5个JavaScript“不良”部分

  3. Is “Class” In ES6 The New “Bad” Part?

    ES6中的“类”是新的“不良”部分吗?

终端改进 (Terminal Improvements)

  1. How to Jazz Up Your Terminal — A Step By Step Guide With Pictures

    如何使您的终端更加爵士乐-带图片的分步指南

  2. Jazz Up Your “ZSH” Terminal In Seven Steps — A Visual Guide

    通过七个步骤使您的“ ZSH”终端变得爵士乐—视觉指南

万维网 (WWW)

  1. A Fascinating And Messy History Of The Web And JavaScript

    Web和JavaScript的迷人历史

虚拟DOM (Virtual DOM)

  1. Inner Workings Of The Virtual DOM

    虚拟DOM的内部运作

React表现 (React Performance)

  1. Two Quick Ways To Reduce React App’s Size In Production

    两种减少React App生产规模的快速方法

  2. Using Preact Instead Of React

    使用Preact代替React

功能编程 (Functional Programming)

  1. JavaScript Is Turing Complete — Explained

    JavaScript正在完善–解释

  2. Functional Programming In JS — With Practical Examples (Part 1)

    JS中的函数式编程—结合实际示例(第1部分)

  3. Functional Programming In JS — With Practical Examples (Part 2)

    JS中的函数式编程—结合实际示例(第2部分)

  4. Why Redux Need Reducers To Be “Pure Functions”

    为什么Redux需要Reducer成为“纯功能”

Web包装 (WebPack)

  1. Webpack — The Confusing Parts

    Webpack —令人困惑的部分

  2. Webpack & Hot Module Replacement [HMR] (under-the-hood)

    Webpack和热模块更换[HMR] ( 后台 )

  3. Webpack’s HMR And React-Hot-Loader — The Missing Manual

    Webpack的HMR和React-Hot-Loader —缺少的手册

Draft.js (Draft.js)

  1. Why Draft.js And Why You Should Contribute

    为什么选择Draft.js,为什么要贡献力量

  2. How Draft.js Represents Rich Text Data

    Draft.js如何表示富文本数据

React And Redux: (React And Redux :)

  1. Step by Step Guide To Building React Redux Apps

    构建React Redux应用程序的逐步指南

  2. A Guide For Building A React Redux CRUD App (3-page app)

    构建React Redux CRUD应用程序指南 (3页应用程序)

  3. Using Middlewares In React Redux Apps

    在React Redux应用程序中使用中间件

  4. Adding A Robust Form Validation To React Redux Apps

    向React Redux应用添加强大的表单验证

  5. Securing React Redux Apps With JWT Tokens

    使用JWT令牌保护React Redux应用程序

  6. Handling Transactional Emails In React Redux Apps

    在React Redux应用程序中处理交易电子邮件

  7. The Anatomy Of A React Redux App

    React Redux应用程序剖析

  8. Why Redux Need Reducers To Be “Pure Functions”

    为什么Redux需要Reducer成为“纯功能”

  9. Two Quick Ways To Reduce React App’s Size In Production

    两种减少React App生产规模的快速方法

如果有用,请分享! 谢谢! ?? (If this was useful, please share it! Thank you! ??)

翻译自: https://www.freecodecamp.org/news/jazz-up-your-bash-terminal-a-step-by-step-guide-with-pictures-80267554cb22/

终端打开后-bash

 类似资料: