ldk0 2017-07-01
Powerline 是 vim、zsh、bash、tmux、IPython、Awesome、bar、fish、lemonbar、pdb、rc、shell、tcsh、wm、i3 和 Qtil 中的一个状态栏插件。它给程序提供了状态栏,并使程序更好看。它用 Python 写成。
它是可扩展的并且功能丰富,它用 Python 写成,非常轻便不需要任何第三方的依赖,只需要一个 Python 解释器。
它的稳定以及可测试的代码库经过完整的测试,并且在 Python 2.6+ 和 Python 3 中工作良好。
最初该状态栏只在 vim 中可用,随后项目进化为许多 Linux 程序如 zsh、bash、tmux、IPython、Awesome、i3 和 Qtil 提供状态栏。
其配置以及配色方案用 JSON 写成。它是一种标准简易的文件格式,可以让用户配置 Powerline 支持的程序。
快速并且轻量级,支持守护进程可以提供更好的性能。
确保你的系统有下面预先要求的包。如果没有,在安装 powerline 之前先安装它们。
对于 Debian 用户,使用 APT 包管理器或者Apt-Get 包管理器安装需要的包。
<span class="pln">$ </span><span class="kwd">sudo </span><span class="kwd">apt-get</span><span class="pln"> install python</span><span class="pun">-</span><span class="pln">pip </span><span class="kwd">git</span>
对于 openSUSE 用户,使用 Zypper 包管理器安装需要的包。
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> zypper install python</span><span class="pun">-</span><span class="pln">pip </span><span class="kwd">git</span>
对于 Fedora 用户,使用 dnf 包管理器安装需要的包。
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> dnf install python</span><span class="pun">-</span><span class="pln">pip </span><span class="kwd">git</span>
对于 Arch Linux 用户,使用 pacman 包管理器安装需要的包。
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> pacman </span><span class="pun">-</span><span class="pln">S python</span><span class="pun">-</span><span class="pln">pip </span><span class="kwd">git</span>
对于 CentOS/RHEL 用户,使用 yum 包管理器安装需要的包。
<span class="pln">$ </span><span class="kwd">sudo </span><span class="kwd">yum</span><span class="pln"> install python</span><span class="pun">-</span><span class="pln">pip </span><span class="kwd">git</span>
在本篇中,我们将向你展示如何安装 Powerline。以及如何在基于 Debian 以及 RHEL 的系统中在 Bash、tumx 和 Vim 中使用。
<span class="pln">$ </span><span class="kwd">sudo</span><span class="pln"> pip install </span><span class="kwd">git</span><span class="pun">+</span><span class="kwd">git</span><span class="pun">:</span><span class="com">//github.com/Lokaltog/powerline</span>
找出 powerline 安装位置以便配置程序。
<span class="pln">$ pip show powerline</span><span class="pun">-</span><span class="pln">status</span>
<span class="typ">Name</span><span class="pun">:</span><span class="pln"> powerline</span><span class="pun">-</span><span class="pln">status</span>
<span class="typ">Version</span><span class="pun">:</span><span class="lit">2.6</span><span class="pun">.</span><span class="pln">dev9999</span><span class="pun">+</span><span class="kwd">git</span><span class="pun">.</span><span class="lit">517f38c566456d65a2170f9bc310e6b4f8112282</span>
<span class="typ">Summary</span><span class="pun">:</span><span class="typ">The</span><span class="pln"> ultimate statusline</span><span class="pun">/</span><span class="pln">prompt utility</span><span class="pun">.</span>
<span class="typ">Home</span><span class="pun">-</span><span class="pln">page</span><span class="pun">:</span><span class="pln"> https</span><span class="pun">:</span><span class="com">//github.com/powerline/powerline</span>
<span class="typ">Author</span><span class="pun">:</span><span class="typ">Kim</span><span class="typ">Silkebaekken</span>
<span class="typ">Author</span><span class="pun">-</span><span class="pln">email</span><span class="pun">:</span><span class="pln"> kim</span><span class="pun">.</span><span class="pln">silkebaekken</span><span class="pun">+</span><span class="kwd">vim</span><span class="lit">@gmail</span><span class="pun">.</span><span class="pln">com</span>
<span class="typ">License</span><span class="pun">:</span><span class="pln"> MIT</span>
<span class="typ">Location</span><span class="pun">:</span><span class="str">/usr/</span><span class="pln">lib</span><span class="pun">/</span><span class="pln">python2</span><span class="pun">.</span><span class="lit">7</span><span class="pun">/</span><span class="pln">site</span><span class="pun">-</span><span class="pln">packages</span>
<span class="typ">Requires</span><span class="pun">:</span>
添加下面的行到 .bashrc
中,它会默认在基础 shell 中启用 powerline。
<span class="kwd">if</span><span class="pun">[</span><span class="pun">-</span><span class="pln">f </span><span class="str">`which powerline-daemon`</span><span class="pun">];</span><span class="kwd">then</span>
<span class="pln">powerline</span><span class="pun">-</span><span class="pln">daemon </span><span class="pun">-</span><span class="pln">q</span>
<span class="pln">POWERLINE_BASH_CONTINUATION</span><span class="pun">=</span><span class="lit">1</span>
<span class="pln">POWERLINE_BASH_SELECT</span><span class="pun">=</span><span class="lit">1</span>
<span class="pun">.</span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">lib</span><span class="pun">/</span><span class="pln">python2</span><span class="pun">.</span><span class="lit">7</span><span class="pun">/</span><span class="pln">site</span><span class="pun">-</span><span class="pln">packages</span><span class="pun">/</span><span class="pln">powerline</span><span class="pun">/</span><span class="pln">bindings</span><span class="pun">/</span><span class="kwd">bash</span><span class="pun">/</span><span class="pln">powerline</span><span class="pun">.</span><span class="pln">sh</span>
<span class="kwd">fi</span>
重新加载 .bashrc
文件使得 powerline 在当前窗口中立即生效。
<span class="pln">$ source </span><span class="pun">~/.</span><span class="pln">bashrc</span>
tmux 是最好的终端仿真程序之一,它提供多窗口以及状态栏,但是相比 powerline 的状态栏看上去不那么好。添加下面的的行到 .tmux.conf
中,它会默认在 tmux 中启用 powerline。如果你没有找到 .tmux.conf
文件,那么创建一个新的。
<span class="com">#</span><span class="kwd">vi</span><span class="pun">~/.</span><span class="pln">tmuc</span><span class="pun">.</span><span class="pln">conf</span>
<span class="pln">source </span><span class="str">"/usr/local/lib/python2.7/site-packages/powerline/bindings/tmux/powerline.conf"</span>
vim 是管理员最爱的文本编辑器之一。添加下面的行到 .vimrc
中,启用 powerline 使 vim 更加强大。注意,在 vim 7.x 中,你可能不会在系统中发现 .vimrc 文件,因此不必担心,创建一个新的文件,并添加下面行。
<span class="com">#</span><span class="kwd">vi</span><span class="pun">~/.</span><span class="pln">vimrc</span>
<span class="kwd">set</span><span class="pln"> rtp</span><span class="pun">+=</span><span class="str">/usr/</span><span class="kwd">local</span><span class="pun">/</span><span class="pln">lib</span><span class="pun">/</span><span class="pln">python2</span><span class="pun">.</span><span class="lit">7</span><span class="pun">/</span><span class="pln">site</span><span class="pun">-</span><span class="pln">packages</span><span class="pun">/</span><span class="pln">powerline</span><span class="pun">/</span><span class="pln">bindings</span><span class="pun">/</span><span class="kwd">vim</span><span class="pun">/</span>
<span class="kwd">set</span><span class="pln"> laststatus</span><span class="pun">=</span><span class="lit">2</span>
<span class="kwd">set</span><span class="pln"> t_Co</span><span class="pun">=</span><span class="lit">256</span>