終端打開后-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" > Te
rminal注意:您可以從此git repo下載各種主題(.terminal文件)。 只需打開
*.terminal
文件以進行安裝,即right-click on the *.terminal file > “open with" > Te
終端”
Go to http://ethanschoonover.com/solarized
前往http://ethanschoonover.com/solarized
- Scroll down and download the Theme (solarized.zip) 向下滾動并下載主題(solarized.zip)
- Extract the solarized.zip file 提取solarized.zip文件
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的特定主題文件。 注意:如果收到來自未知開發人員的警告,請右鍵單擊該文件,然后選擇“打開方式”>“終端 ”。
- At this point, you have the Theme installed into your Terminal. We just need to make it a default Theme. 此時,您已將主題安裝到終端中。 我們只需要使其成為默認主題即可。
- 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
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使用默認情況下不可用的各種圖標和字體。 因此,我們需要安裝字體。
步驟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點綴字體,我們完成了!
- Open Terminal > Preferences > Text 打開終端>首選項>文本
Select Solarized Dark ansi Theme
選擇日光化深色ansi主題
- Click on the “Font” button — This opens up “Fonts” dialog 單擊“字體”按鈕-這將打開“字體”對話框
- 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! ??? ??)
我的其他帖子 (My Other Posts)
https://medium.com/@rajaraodv/latest
https://medium.com/@rajaraodv/latest
ECMAScript 2015+ (ECMAScript 2015+)
Check out these useful ECMAScript 2015 (ES6) tips and tricks
查看這些有用的ECMAScript 2015(ES6)提示和技巧
5 JavaScript “Bad” Parts That Are Fixed In ES6
ES6中修復的5個JavaScript“不良”部分
Is “Class” In ES6 The New “Bad” Part?
ES6中的“類”是新的“不良”部分嗎?
終端改進 (Terminal Improvements)
How to Jazz Up Your Terminal — A Step By Step Guide With Pictures
如何使您的終端更加爵士樂-帶圖片的分步指南
Jazz Up Your “ZSH” Terminal In Seven Steps — A Visual Guide
通過七個步驟使您的“ ZSH”終端變得爵士樂—視覺指南
萬維網 (WWW)
A Fascinating And Messy History Of The Web And JavaScript
Web和JavaScript的迷人歷史
虛擬DOM (Virtual DOM)
Inner Workings Of The Virtual DOM
虛擬DOM的內部運作
React表現 (React Performance)
Two Quick Ways To Reduce React App’s Size In Production
兩種減少React App生產規模的快速方法
Using Preact Instead Of React
使用Preact代替React
功能編程 (Functional Programming)
JavaScript Is Turing Complete — Explained
JavaScript正在完善–解釋
Functional Programming In JS — With Practical Examples (Part 1)
JS中的函數式編程—結合實際示例(第1部分)
Functional Programming In JS — With Practical Examples (Part 2)
JS中的函數式編程—結合實際示例(第2部分)
Why Redux Need Reducers To Be “Pure Functions”
為什么Redux需要Reducer成為“純功能”
Web包裝 (WebPack)
Webpack — The Confusing Parts
Webpack —令人困惑的部分
Webpack & Hot Module Replacement [HMR] (under-the-hood)
Webpack和熱模塊更換[HMR] ( 后臺 )
Webpack’s HMR And React-Hot-Loader — The Missing Manual
Webpack的HMR和React-Hot-Loader —缺少的手冊
Draft.js (Draft.js)
Why Draft.js And Why You Should Contribute
為什么選擇Draft.js,為什么要貢獻力量
How Draft.js Represents Rich Text Data
Draft.js如何表示富文本數據
React And Redux: (React And Redux :)
Step by Step Guide To Building React Redux Apps
構建React Redux應用程序的逐步指南
A Guide For Building A React Redux CRUD App (3-page app)
構建React Redux CRUD應用程序指南 (3頁應用程序)
Using Middlewares In React Redux Apps
在React Redux應用程序中使用中間件
Adding A Robust Form Validation To React Redux Apps
向React Redux應用添加強大的表單驗證
Securing React Redux Apps With JWT Tokens
使用JWT令牌保護React Redux應用程序
Handling Transactional Emails In React Redux Apps
在React Redux應用程序中處理交易電子郵件
The Anatomy Of A React Redux App
React Redux應用程序剖析
Why Redux Need Reducers To Be “Pure Functions”
為什么Redux需要Reducer成為“純功能”
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