23

安装Powerline并配置Vim、Bash、tmux、IPython、pdb

 4 years ago
source link: https://note.qidong.name/2020/09/install-powerline/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

安装Powerline并配置Vim、Bash、tmux、IPython、pdb

2020-09-21 21:59:17 +08  字数:1546  标签: Bash Python Linux

使用Bash,是Linux下开发的基本技能。 虽然也有zsh、fish等流行Shell,但Bash是多数情况下的默认,基本中的基本。

Shell的提示符(Prompt),默认在root下是#,在普通用户下是$,但这只能提示用户权限信息。 Bash默认情况下做了一些强化,但信息较少,而且不够美观。

本文主要介绍基于Powerline的CLI美化配置。

Powerline简介

Powerline一开始是一个Vim的状态栏插件,后来发展成为Bash、zsh、fish等Shell的终端提示工具。 此外,还支持tmux、IPython、Awesome、i3、Qtile等软件。

Powerline in Vim (and tmux)

在这个增强的状态栏中,我们可以看到Vim模式、Git分支、文件路径、Git状态等信息。 不仅美观,而且实用。

在Bash中,Powerline也同样强大。 由于场景与Vim不同,因此显示内容也不同,默认有用户名、当前路径、后台任务数等,远程模式下还有hostname。 根据需要,也可以添加更多的系统元素,如上一命令返回值、时间、电池等。

Powerline in Bash (and tmux)

在tmux中,默认有Window编号、开机时间、日期、hostname等信息。

安装软件

一般情况下,直接使用pip即可安装。 为了便于多用户使用,通常全局安装。 需要特别注意的是,包被占,因在pypi.org的包名是powerline-status

sudo pip install powerline-status

似乎是由于作者失联,powerline-status的版本停留在了2.7,目前最新是2.8.1。 如果需要更新,可以使用developmaster分支。

sudo pip install git+https://github.com/powerline/powerline.git@develop

安装字体

Powerline在显示时,使用了特殊字体。 一般的字体配置,不能正确地展示。 因此,需要安装其字体。

sudo apt install fonts-powerline

如果在其它系统与环境,可以参考powerline-fonts的指导,手动安装。

git clone https://github.com/powerline/fonts.git
cd fonts
./install.sh

配置

Powerline支持多种使用场景。 其中,不同场景下需要不同的配置。

以下介绍五个场景的配置:

  • IPython

Vim

Vim中,Powerline只是其状态栏插件。 在~/.vimrc中,可以使用插件的方式添加。

Bundle 'powerline/powerline', {'rtp': 'powerline/bindings/vim'}
" or
Plug 'powerline/powerline', {'rtp': 'powerline/bindings/vim'}

也可以直接复用系统安装的powerline-status

python3 << endpython
from powerline.vim import setup as powerline_setup
powerline_setup()
del powerline_setup
endpython

以上两种配置方式,流行的是第一种,但这里推荐第二种。 第一种有若干问题,某些场景下会报错提示有两个powerline

Bash

POWERLINE_HOME=$(python3 -c "
import pkg_resources

try:
    dist = pkg_resources.get_distribution('powerline-status')
    print(dist.location)
except pkg_resources.DistributionNotFound:
    raise SystemExit(1)
")
if [ -d "$POWERLINE_HOME" ]
then
    source "$POWERLINE_HOME/powerline/bindings/bash/powerline.sh"
    export POWERLINE_HOME
fi

tmux

~/.tmux.conf文件中,添加一行:

source "$POWERLINE_HOME/powerline/bindings/tmux/powerline.conf"

其中,$POWERLINE_HOME是前面Bash配置中export的那个变量。 因此,tmux的这个配置依赖于Bash的配置。

IPython

新增文件~/.ipython/profile_default/ipython_config.py,添加以下内容:

from powerline.bindings.ipython.since_7 import PowerlinePrompts
c = get_config()
c.TerminalInteractiveShell.simple_prompt = False
c.TerminalInteractiveShell.prompts_class = PowerlinePrompts

不同IPython版本,需要使用不同的配置。 这里是针对最新的7.x版本的配置,所以是since_7。 对旧版本,需要使用旧的配置,可参考《other.rst#ipython-prompt》。

注意:由于since_7是在Powerline 2.8加入的功能,因此必须使用源码安装的方式。 由于相同原因,官方文档也无法更新,因此最新文档只能查看源码中的文档文件。

pdb

使用以下命令,替代pdb,即可获得Powerline效果:

python3 -m powerline.bindings.pdb

当然,这个命令比较长,不方便。 可以使用以下alias

alias pdb='python3 -m powerline.bindings.pdb'

结语

Powerline的这些增强与美化中,Vim、Bash和tmux是最有用的,另外两个纯粹只是美化而已。

CLI本身是高效的,但是也未免乏味。 有了Powerline,不仅显著提高了颜值,更是提供了更多相关信息。 习惯之后,会大幅提高工作效率。

参考


Recommend

  • 114

    报错信息:pythonFailedbuildingwheelforscandir解决方法wgethttp://nipy.bic.berkeley.edu/scipy_installers/wheel-0.24.0-py2.py3-none-any.whlpipinstallwheel-0.24.0-py2.py3-non-any.whlyuminstallpython-devel-y

  • 21

    Table of Contents有一些 vim 主题(如 gruvbox 或 solarized8)在 GUI 和终端下效果不同,有可能是因为这个主题需要 true color (2...

  • 30

    Tmux and Vim: Copy and Paste on macOS Sierra Posted: 2017-03-22 - Last updated: 2019-06-05 Tagged

  • 9
    • www.80shihua.com 4 years ago
    • Cache

    vim+tmux 真彩色256color配置

    vim+tmux 真彩色256color配置 vim是我们最喜爱的编辑器,tmux是我们最喜爱的终端管理器,它们的搭配可以让你的工作效率提升到难以想象的高度。默认情况下,linux的终端是8位的彩色配置,也就说它的颜色过于单一,然而其实大部分情况下它都是支持...

  • 15
    • www.producthunt.com 4 years ago
    • Cache

    Learn Linux, Vim, Git, Tmux, Gpg and more

    Learn Linux, Vim, Git, Tmux, Gpg and more

  • 12
    • www.80shihua.com 3 years ago
    • Cache

    tmux 安装配置主题

    窗口管理工具tmux是可以配置主题的,配置之前,首先需要安装插件管理器 下载插件管理工具tpm git clone https://github.com/tmux-plugins/tpm ~/.tmux/plugins/tpm 安装tpm 修改tmux配置文件.tmux.conf,添加...

  • 10
    • blackdragonf.github.io 3 years ago
    • Cache

    Vim+Tmux配置Scheme编程环境

    Vim+Tmux配置Scheme编程环境 12月 11, 2017 发布在

  • 11

    Page not found · GitHub PagesThere isn't a GitHub Pages site here. Did you mean to visit mjason.github.io? Please note that this site belongs to a GitHub u...

  • 10
    • unique-pure.github.io 3 years ago
    • Cache

    tmux与vim教程

    1. Shell概论Shell是一个用C语言编写的程序,它诞生于Unix,是我们通过命令行与Unix/Linux交互的工具。笼统地说:Shell既是一种命令语言,又是一种程序设计语言。 而Shell脚本是一种为Shell编写的脚本程序,有的时候也被称为Shel...

  • 28

    Introduction If you write code in multiple languages you may have found it tiresome to maintain an IDE for each. After some experimentation I found the combination of Vim and Tmux to be the ideal solution for my case. T...

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK