Installing Powerline on Ubuntu Linux

本文详细介绍了如何在Ubuntu的Universe仓库中安装Powerline,以及如何配置Bash、Vim、tmux以显示Git仓库信息、状态栏和自定义shell提示。还指导了如何根据需求定制Powerline的外观和行为。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Powerline is a text-based tool that provides useful information in a variety of contexts. The following demo shows Powerline displaying information about a Git repository:

Install Powerline

You can install Powerline from the Universe repository of Ubuntu:

  1. Add the Universe repository:
    sudo add-apt-repository universe
    
  2. Install Powerline
    sudo apt install --yes powerline
    

Configure Bash

To configure Powerline for bash, add the following lines to your $HOME/.bashrc file:

# Powerline configuration
if [ -f /usr/share/powerline/bindings/bash/powerline.sh ]; then
  powerline-daemon -q
  POWERLINE_BASH_CONTINUATION=1
  POWERLINE_BASH_SELECT=1
  source /usr/share/powerline/bindings/bash/powerline.sh
fi

To apply the changes to your current terminal:

source ~/.bashrc

After running the previous command or restarting your terminal, the Powerline segments appear in your prompt.

Configure Vim

To use Powerline, Vim requires support for Python 3. You can check the features included in your installation with the following command:

vim --version

Look for the python3 entry, which must have a plus sign (+) next to it to indicate that the feature is available. If your version of vim doesn’t include support for Python 3, you can install the latest vim package, which at the time of this writing includes support for Python 3:

sudo apt update
sudo apt install --yes vim

To configure Powerline for Vim, add the following lines to your $HOME/.vimrc file:

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

set laststatus=2

The laststatus setting displays the status bar in Vim and makes Powerline visible by default.

Configure tmux

To configure Powerline in tmux, add the following to your ~/.tmux.conf file:

set -g default-terminal "screen-256color"
source "/usr/share/powerline/bindings/tmux/powerline.conf"

You must set the correct value for your terminal using the default-terminal setting. If you don’t configure the correct value for your terminal, you might run into some issues. For example, Vim inside of tmux doesn’t show colored Powerline segments. The screen-256color or xterm-256color values work fine in our environments.

Edit your Powerline configuration

You can customize what segments appear in Powerline, or even the behavior of specific segments. Follow these instructions to customize your Powerline installation:

  1. Copy the /usr/share/powerline/config_files/ folder to $HOME/.config/powerline:
    mkdir -p $HOME/.config/powerline
    cp -R /usr/share/powerline/config_files/* \
          $HOME/.config/powerline/
    
  2. Edit the files there according to your needs. A good starting point is the $HOME/.config/powerline/config.json file.
  3. Reload the Powerline daemon:
    powerline-daemon --replace
    

The following example shows how to configure Powerline on the shell to behave as the demo shown in the introduction of this guide:

  1. To show the vcs segment—which displays information about git repositories—on the left side of the shell, replace the default theme with the default_leftonly theme in the $HOME/.config/powerline/config.json file:
    ···
    "shell": {
      "colorscheme": "default",
      "theme": "default_leftonly",
      "local_themes": {
        "continuation": "continuation",
        "select": "select"
      }
    },
    ···
    
  2. To make the vcs segment display in a different color when the git repository is dirty, add the status_colors attribute to the vcs segment in the $HOME/.config/powerline/themes/shell/default_leftonly.json file:
    ···
    {
      "function": "powerline.segments.common.vcs.branch",
      "priority": 40,
      "args": { "status_colors": true }
    }
    ···
    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

白敬亭分亭

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值