Powerline是一款优秀的Vim编辑器状态行插件。本插件使用Python开发,主要用于显示状态行和提示信息。适用于很多软件,如bash、zsh、tmux等。特性用python编写,使其更具可扩展性和功能丰富稳定且易于测试的代码库,兼容python2.6+和python3支持多种Linux函数和工具提示和状态栏通过JSON保存配置和配色方案快速简单Powerline效果截图Vim中的Powerline状态线效果在本文中,我将解释如何安装Powerline及其字体,以及如何使用Bash和Vim支持Powerline。第一步:准备安装Powerline所需的软件由于与其他无关项目的命名冲突,powerline只能放在PyPI(Python包索引)中的powerline-status包下。为了安装包,你需要先准备pip(这个工具专门用于Python包管理)工具。所以首先在linux系统下安装pip工具。在Debian、Ubuntu和LinuxMint中安装pip#apt-getinstallpython-pip示例输出:Readingpackagelists...DoneBuildingdependencytreeReadingstateinformation...DoneRecommendedpackages:python-dev-allpython-wheelThefollowingNEWpackageswillbeinstalled:python-pip0upgraded,1newlyinstalled,0toremoveand533notuptoperchofarget9terkspacealditionedhttpwillusb7,47://archive.ubuntu.com/ubuntu/trusty-updates/universepython-pipall1.5.4-1ubuntu3[97.2kB]Fetched97.2kBin1s(73.0kB/s)Selectingpreviouslyunselectedpackagepython-pip。(正在读取数据库...216258个文件和目录当前安装。)准备解压.../python-pip_1.5.4-1ubuntu3_all.deb...解压python-pip(1.5.4-1ubuntu3)...处理触发forman-db(2.6.7.1-1ubuntu1)...Settinguppython-pip(1.5.4-1ubuntu3)...在CentOS、RHEL和Fedora中安装pip在类Fedora系统中,需要先打开epel仓库,然后安装pip包如下。#yuminstallpython-pip#dnfinstallpython-pip[Fedora22+及以上]示例输出:Installing:python-pipnoarch7.1.0-1.el7epel1.5MTransactionSummary===================================================================================Install1PackageTotaldownloadsize:1.5MInstalledsize:6.6MIsthisok[y/d/N]:yDownloadingpackages:python-pip-7.1.0-1.el7.noarch.rpm|1.5MB00:00:01RunningtransactioncheckRunningtransactiontestTransactiontestsucceededRunningtransactionInstalling:python-pip-7.1.0-1.el7.noarch1/1Verifying:python-pip-7.1.0-1.el7.noarch1/1Installed:python-pip.noarch0:7.1.0-1.el7完成!第2步:在Linux上安装Powerline现在可以从Git存储库安装Powerline的最新开发版本。在此之前,系统需要安装Git工具,才能从仓库中拉取代码。#apt-getinstallgit#yuminstallgit#dnfinstallgit然后你可以通过pip命令安装Powerline。#pipinstallgit+git://github.com/powerline/powerline示例输出:Cloninggit://github.com/powerline/powerlineto/tmp/pip-WAlznH-buildRunningsetup.py(path:/tmp/pip-WAlznH-build/setup.py)egg_infoforpackagefromgit+git://github.com/Lokaltog/powerlinewarning:nopreviously-includedfilesmatching'*.pyc'foundunderdirectory'powerline/bindings'warning:nopreviously-includedfilesmatching'*.pyo'foundunderdirectory'powerline/bindings'安装收集的包:powerline-statusFoundexistinginstallation:powerline-status2.2Uninstallingpowerline-status:Successfullyuninstalledpowerline-statusRunningsetup.pyinstallforpowerline-statuswarning:nopreviously-includedfilesmatching'*.pyc'foundunderdirectory'powerline/bindings'warning:nopreviously-includedfilessmatching'*.pyo'foundunderdirectory'电力线/绑定'changingmodeofbuild/scripts-2.7/powerline-lintfrom644to755changingmodeofbuild/scripts-2.7/powerline-daemonfrom644to755changingmodeofbuild/scripts-2.7/powerline-renderfrom644to755changingmodeofbuild/scripts-2.7/powerline-configfrom644to755changingmodeof/usr/local/bin/powerline-configto755changingmodeof/usr/local/bin/powerline-lintto755changingmodeof/usr/local/bin/powerline-renderto755changingmodeof/usr/local/bin/powerline-daemonto755Successfullyinstalledpowerline-statusCleaningup...第3步:在Linux中安装Powerline字体Powerline使用特殊符号来显示特殊的箭头效果和符号内容供开发者使用,所以你的系统中必须有符号字体或补丁字体。通过下面的wget命令下载最新的系统字体和字体配置文件。#wgethttps://github.com/powerline/powerline/raw/develop/font/PowerlineSymbols.otf#wgethttps://github.com/powerline/powerline/raw/develop/font/10-powerline-symbols.conf然后你将下载好的字体放到字体目录/usr/share/fonts或/usr/local/share/fonts中,也可以通过xsetq命令找到有效的字体目录。#mvPowerlineSymbols.otf/usr/share/fonts/接下来您需要使用以下命令更新系统的字体缓存。#fc-cache-vf/usr/share/fonts/其次安装字体配置文件。#mv10-powerline-symbols.conf/etc/fonts/conf.d/注意:如果没有出现对应的符号,可以尝试关闭终端会话,重启X窗口,这样才会生效。第四步:为BashShell和Vim状态行设置Powerline本节将介绍在bashshell和vim编辑器中Powerline的配置。首先通过在~/.bashrc中添加以下内容将终端设置为256色。exportTERM="screen-256color"在BashShell中打开Powerline如果你想在bashshell中默认打开Powerline,你可以在~/.bashrc中添加以下内容。首先通过以下命令获取powerline的安装位置。#pipshowpowerline-statusName:powerline-statusVersion:2.2.dev9999-git.aa33599e3fb363ab7f2744ce95b7c6465eef7f08Location:/usr/local/lib/python2.7/dist-packagesRequires:找到powerline的具体位置后,根据你的情况替换成下面一行system/usr/local/lib/python2.7/dist-packages对应位置。powerline-daemon-qPOWERLINE_BASH_CONTINUATION=1POWERLINE_BASH_SELECT=1./usr/local/lib/python2.7/dist-packages/powerline/bindings/bash/powerline.sh然后注销再登录。现在powerline的状态行应该显示如下。BashPowerlineStatuslines现在切换目录并观察面包屑提示中显示当前路径的变化。如果远程Linux服务器上安装了powerline,可以在后台看到挂起的任务,用ssh登陆的时候,会看到提示添加hostname。在Vim中打开电力线如果你喜欢使用vim,有一个强大的vim插件。可以在~/.vimrc中添加以下内容来打开插件(LCTT译注:注意,还需要根据自己的系统情况修改路径)。setrtp+=/usr/local/lib/python2.7/dist-packages/powerline/bindings/vim/setlaststatus=2sett_Co=256然后你打开vim后会看到一个新的状态行:VimPowerlineStatuslinesSummaryPowerline可以在一个某些软件提供了色彩鲜艳、美观的状态行和提示内容,有利于编程环境。希望本指南对您有所帮助,如果您需要帮助或有任何好的想法,请给我留言。关于作者:我是RaviSaive,TecMint的作者。喜欢分享技巧和想法的计算机极客和Linux专家。我的大部分服务都运行在开源平台Linux中。在Twitter、Facebook和Google+上关注我。
