溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Linux中如何使用Powerline

發(fā)布時間:2021-10-28 17:29:39 來源:億速云 閱讀:507 作者:小新 欄目:系統(tǒng)運維

這篇文章主要介紹了Linux中如何使用Powerline,具有一定借鑒價值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。

Powerline 是一個極棒的 Vim 編輯器的狀態(tài)行插件,這個插件是使用 Python 開發(fā)的,主要用于顯示狀態(tài)行和提示信息,適用于很多軟件,比如  bash、zsh、tmux 等等。

特色

  1. 使用 python 編寫,使其更具擴展性且功能豐富

  2. 穩(wěn)定易測的代碼庫,兼容 python 2.6+ 和 python 3

  3. 支持多種 Linux 功能及工具的提示和狀態(tài)欄

  4. 通過 JSON 保存配置和顏色方案

  5. 快速、輕量級,具有后臺守護進程支持,提供更佳的性能

Powerline 效果截圖

Linux中如何使用Powerline

Vim 中 Powerline 狀態(tài)行效果

在本文中,我會介紹如何安裝 Powerline 及其字體,以及如何在 RedHat 和 Debian 類的系統(tǒng)中使 Bash 和 Vim 支持  Powerline。

***步:準備好安裝 Powerline 所需的軟件

由于和其它無關(guān)項目之間存在命名沖突,因此 powerline 只能放在 PyPI(Python Package Index)中的  powerline-status 包下.

為了從 PyPI 中安裝該包,需要先準備好 pip(該工具專門用于 Python 包的管理)工具。所以首先要在 Linux 系統(tǒng)下安裝好 pip  工具。

在 Debian、Ubuntu 和 Linux Mint 中安裝 pip

# apt-get install python-pip

示例輸出:

Reading package lists... Done Building dependency tree        Reading state information... Done Recommended packages: python-dev-all python-wheel The following NEW packages will be installed: python-pip 0 upgraded, 1 newly installed, 0 to remove and 533 not upgraded. Need to get 97.2 kB of archives. After this operation, 477 kB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu/ trusty-updates/universe python-pip all 1.5.4-1ubuntu3 [97.2 kB] Fetched 97.2 kB in 1s (73.0 kB/s)      Selecting previously unselected package python-pip. (Reading database ... 216258 files and directories currently installed.) Preparing to unpack .../python-pip_1.5.4-1ubuntu3_all.deb ... Unpacking python-pip (1.5.4-1ubuntu3) ... Processing triggers for man-db (2.6.7.1-1ubuntu1) ... Setting up python-pip (1.5.4-1ubuntu3) ...

在 CentOS、RHEL 和 Fedora 中安裝 pip

在 Fedora 類系統(tǒng)中,需要先打開 epel 倉庫,然后按照如下方法安裝 pip 包。

# yum install python-pip           # dnf install python-pip                     [Fedora 22+ 以上]

示例輸出:

Installing: python-pip          noarch          7.1.0-1.el7             epel          1.5 M Transaction Summary ================================================================================= Install  1 Package Total download size: 1.5 M Installed size: 6.6 M Is this ok [y/d/N]: y Downloading packages: python-pip-7.1.0-1.el7.noarch.rpm                         | 1.5 MB  00:00:01      Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : python-pip-7.1.0-1.el7.noarch                                 1/1  Verifying  : python-pip-7.1.0-1.el7.noarch                                 1/1  Installed: python-pip.noarch 0:7.1.0-1.el7                                                 Complete!

第二步:在 Linux 中安裝 Powerline

現(xiàn)在可以從 Git 倉庫中安裝 Powerline 的***開發(fā)版。在此之前系統(tǒng)需要安裝好 Git 工具以便可以從倉庫拉下代碼。

# apt-get install git # yum install git # dnf install git

然后你可以通過 pip 命令安裝 Powerline。

# pip install git+git://github.com/powerline/powerline

示例輸出:

Cloning git://github.com/powerline/powerline to /tmp/pip-WAlznH-build Running setup.py (path:/tmp/pip-WAlznH-build/setup.py) egg_info for package from git+git://github.com/Lokaltog/powerline warning: no previously-included files matching '*.pyc' found under directory 'powerline/bindings' warning: no previously-included files matching '*.pyo' found under directory 'powerline/bindings' Installing collected packages: powerline-status Found existing installation: powerline-status 2.2 Uninstalling powerline-status: Successfully uninstalled powerline-status Running setup.py install for powerline-status warning: no previously-included files matching '*.pyc' found under directory 'powerline/bindings' warning: no previously-included files matching '*.pyo' found under directory 'powerline/bindings' changing mode of build/scripts-2.7/powerline-lint from 644 to 755 changing mode of build/scripts-2.7/powerline-daemon from 644 to 755 changing mode of build/scripts-2.7/powerline-render from 644 to 755 changing mode of build/scripts-2.7/powerline-config from 644 to 755 changing mode of /usr/local/bin/powerline-config to 755 changing mode of /usr/local/bin/powerline-lint to 755 changing mode of /usr/local/bin/powerline-render to 755 changing mode of /usr/local/bin/powerline-daemon to 755 Successfully installed powerline-status Cleaning up...

第三步:在 Linux 中安裝 Powerline 的字體

Powerline 使用特殊的符號來為開發(fā)者顯示特殊的箭頭效果和符號內(nèi)容。因此你的系統(tǒng)中必須要有符號字體或者補丁過的字體。

通過下面的 wget 命令下載***的系統(tǒng)字體及字體配置文件。

# wget https://github.com/powerline/powerline/raw/develop/font/PowerlineSymbols.otf # wget https://github.com/powerline/powerline/raw/develop/font/10-powerline-symbols.conf

然后你將下載的字體放到字體目錄下 /usr/share/fonts 或者 /usr/local/share/fonts,或者你可以通過 xset q  命令找到一個有效的字體目錄。

# mv PowerlineSymbols.otf /usr/share/fonts/

接下來你需要通過如下命令更新你系統(tǒng)的字體緩存。

# fc-cache -vf /usr/share/fonts/

其次安裝字體配置文件。

# mv 10-powerline-symbols.conf /etc/fonts/conf.d/

注意:如果相應(yīng)的符號沒有出現(xiàn),可以嘗試關(guān)閉終端會話并重啟 X window,這樣就會生效了。

第四步:給 Bash Shell 和 Vim 狀態(tài)行設(shè)置 Powerline

在這一節(jié)將介紹 bash shell 和 vim 編輯器中關(guān)于 Powerline 的配置。首先通過在 ~/.bashrc 中添加如下內(nèi)容以便設(shè)置終端為  256 色。

export TERM="screen-256color"

打開 Bash Shell 中的 Powerline

如果希望在 bash shell 中默認打開 Powerline,可以在 ~/.bashrc 中添加如下內(nèi)容。

首先通過如下命令獲取 powerline 的安裝位置。

# pip show powerline-status Name: powerline-status Version: 2.2.dev9999-git.aa33599e3fb363ab7f2744ce95b7c6465eef7f08 Location: /usr/local/lib/python2.7/dist-packages Requires:

一旦找到 powerline 的具體位置后,根據(jù)你系統(tǒng)的情況替換到下列行中的 /usr/local/lib/python2.7/dist-packages  對應(yīng)的位置。

powerline-daemon -q POWERLINE_BASH_CONTINUATION=1 POWERLINE_BASH_SELECT=1 . /usr/local/lib/python2.7/dist-packages/powerline/bindings/bash/powerline.sh

然后退出后重新登錄,現(xiàn)在 powerline 的狀態(tài)行應(yīng)該如下顯示了。

Linux中如何使用Powerline

Bash Powerline Statuslines

現(xiàn)在切換目錄并注意顯示你當前路徑的面包屑導航提示的變化。

如果遠程 Linux 服務(wù)器上安裝了 powerline,你能看到后臺掛起的任務(wù),當你用 ssh 登錄上去時,會看到該提示增加了主機名。

在 Vim 中打開 Powerline

如果你喜歡使用 vim,正好有一個 vim 的強力插件??梢栽?~/.vimrc 中添加如下內(nèi)容打開該插件(LCTT  譯注:注意同樣需要根據(jù)你的系統(tǒng)情況修改路徑)。

set rtp+=/usr/local/lib/python2.7/dist-packages/powerline/bindings/vim/ set laststatus=2 set t_Co=256

然后你打開 vim 后會看到一個新的狀態(tài)行:

Linux中如何使用Powerline

感謝你能夠認真閱讀完這篇文章,希望小編分享的“Linux中如何使用Powerline”這篇文章對大家有幫助,同時也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識等著你來學習!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI