终端打开后-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将如下所示。 让我们继续添加主题,字体等。
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" > Te
rminal注意:您可以从此git repo下载各种主题(.terminal文件)。 只需打开
*.terminal
文件以进行安装,即right-click on the *.terminal file > “open with" > Te
终端”
Open the osx-terminal.app-colors-solarized folder. This folder contains Theme for the terminal.
打开osx-terminal.app-colors-solarized文件夹。 该文件夹包含终端的主题。
Double click “Solarized Dark ansi.terminal” file — This 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的特定主题文件。 注意:如果收到来自未知开发人员的警告,请右键单击该文件,然后选择“打开方式”>“终端 ”。
From now on, your Terminal should like below.
从现在开始,您的终端应如下所示。
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.
它使终端提示如下所示。
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
Install pip by running the following command
通过运行以下命令来安装pip
$ sudo easy_install pip
$ sudo easy_install pip
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
进行重置。
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
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
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 oddpowerline-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使用默认情况下不可用的各种图标和字体。 因此,我们需要安装字体。
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的图标和字体。
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字体的常规和斜体版本。
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点缀字体,我们完成了!
Select Solarized Dark ansi Theme
选择日光化深色ansi主题
Completely quit the Terminal (Terminal > Quit Terminal) and then reopen it.
完全退出终端(终端>退出终端),然后重新打开。
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状态信息。
pip install --user powerline-gitstatus
Note: “ — user” command is required to install it in the user’s profile.
注意:需要“ —用户”命令才能将其安装在用户的配置文件中。
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.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": []
}
}
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
。
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
https://medium.com/@rajaraodv/latest
https://medium.com/@rajaraodv/latest
Check out these useful ECMAScript 2015 (ES6) tips and tricks
How to Jazz Up Your Terminal — A Step By Step Guide With Pictures
Functional Programming In JS — With Practical Examples (Part 1)
Functional Programming In JS — With Practical Examples (Part 2)
Webpack & Hot Module Replacement [HMR] (under-the-hood)
Webpack和热模块更换[HMR] ( 后台 )
A Guide For Building A React Redux CRUD App (3-page app)
构建React Redux CRUD应用程序指南 (3页应用程序)
终端打开后-bash