Powerline là plugin statusline tuyệt vời cho trình soạn thảo Vim, được phát triển bằng Python và cung cấp statuslines và prompts cho nhiều ứng dụng khác như bash, zsh, tmux và hơn nữa.
Tính năng
- Viết bằng Python, làm cho nó mở rộng và giàu tính năng.
- Code base ổn định và có thể test, hoạt động tốt với Python 2.6+ và Python 3.
- Hỗ trợ prompts và statuslines trong nhiều tiện ích và công cụ Linux.
- Cấu hình và màu trang trí dùng JSON.
- Nhanh và nhẹ, hỗ trợ daemon, hiệu năng tốt hơn.
Ảnh chụp màn hình Powerline


Bài này hướng dẫn cài Powerline và Powerline fonts và dùng với Bash và Vim trên hệ thống RedHat và Debian based.
Bước 1: Cài đặt yêu cầu chung cho Powerline
Do xung đột tên với dự án không liên quan, chương trình powerline trên PyPI (Python Package Index) có tên gói powerline-status.
Để cài gói từ PyPI, cần 'pip' (công cụ quản lý gói cài gói Python). Hãy cài pip trước.
Cài Pip trên Debian, Ubuntu và Linux Mint
# apt-get install python-pip
Kết quả mẫu
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 https://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) ...
Cài Pip trên CentOS, RHEL và Fedora
Trên hệ thống Fedora-based, cần bật epel-repository trước rồi cài pip:
# yum install python-pip # dnf install python-pip [Trên Fedora 22+]
Kết quả mẫu
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!
Bước 2: Cài đặt công cụ Powerline trên Linux
Bây giờ cài Powerline phiên bản phát triển mới nhất từ kho Git. Hệ thống cần gói git để tải gói từ Git.
# apt-get install git # yum install git # dnf install git
Tiếp theo cài Powerline với lệnh pip:
# pip install git+git://github.com/Lokaltog/powerline
Kết quả mẫu
Cloning git://github.com/Lokaltog/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...
Bước 3: Cài đặt Powerline Fonts trên Linux
Powerline dùng glyphs đặc biệt để hiển thị hiệu ứng mũi tên và ký hiệu cho developer. Cần font symbol hoặc font patched cài trên hệ thống.
Tải phiên bản mới nhất font symbol và file cấu hình fontconfig bằng wget:
# wget https://github.com/powerline/powerline/raw/develop/font/PowerlineSymbols.otf # wget https://github.com/powerline/powerline/raw/develop/font/10-powerline-symbols.conf
Di chuyển font vào thư mục font, /usr/share/fonts/ hoặc /usr/local/share/fonts hoặc lấy đường dẫn font hợp lệ bằng xset q.
# mv PowerlineSymbols.otf /usr/share/fonts/
Cập nhật font cache hệ thống:
# fc-cache -vf /usr/share/fonts/
Cài file fontconfig:
# mv 10-powerline-symbols.conf /etc/fonts/conf.d/
Lưu ý: Nếu symbol tùy chỉnh không hiện, hãy đóng tất cả terminal và khởi động lại X window để thay đổi có hiệu lực.
Bước 4: Cấu hình Powerline cho Bash Shell và Vim Statuslines
Phần này cấu hình Powerline cho bash shell và vim editor. Trước hết làm terminal hỗ trợ 256color bằng cách thêm dòng sau vào ~/.bashrc:
export TERM="screen-256color"
Kích hoạt Powerline trên Bash Shell
Để bật Powerline mặc định trong bash shell, thêm đoạn sau vào ~/.bashrc.
Trước hết lấy vị trí cài powerline:
# pip show powerline-status Name: powerline-status Version: 2.2.dev9999-git.aa33599e3fb363ab7f2744ce95b7c6465eef7f08 Location: /usr/local/lib/python2.7/dist-packages Requires:
Khi biết vị trí thực của powerline, thay thế vị trí trong dòng dưới theo hệ thống:
powerline-daemon -q POWERLINE_BASH_CONTINUATION=1 POWERLINE_BASH_SELECT=1 . /usr/local/lib/python2.7/dist-packages/powerline/bindings/bash/powerline.sh
Đăng xuất và đăng nhập lại, sẽ thấy powerline statusline như hình.

Thử chuyển thư mục khác và quan sát prompt "breadcrumb" thay đổi hiển thị vị trí hiện tại.
Cũng xem được background job đang chờ và nếu powerline cài trên máy Linux từ xa, prompt thêm hostname khi kết nối SSH.
Kích hoạt Powerline cho Vim
Nếu vim là trình soạn thảo yêu thích, may mắn có plugin mạnh cho vim. Để bật plugin, thêm dòng sau vào ~/.vimrc:
set rtp+=/usr/local/lib/python2.7/dist-packages/powerline/bindings/vim/ set laststatus=2 set t_Co=256
Khởi chạy vim và thấy status line mới:

Tóm tắt
Powerline giúp thiết lập statuslines và prompts đẹp, nhiều màu cho nhiều ứng dụng, tốt cho môi trường coding. Hy vọng hướng dẫn hữu ích và nhớ bình luận nếu cần giúp đỡ hoặc ý tưởng thêm.