10.9K Star!超酷的 Linux 桌面状态栏工具
The following article is from 开源前哨 Author 小秋
【导语】:超酷的 Linux 桌面状态栏工具。
简介
Polybar 是一个用于创建状态栏的快速且易于使用的工具,为用户桌面环境构建漂亮且高度可定制的状态栏。状态栏能展示最常用服务的相关信息,包括:
系统托盘图标 窗口标题 MPD 的播放控制和状态显示 ALSA 和 PulseAudio 的音量控制 bspwm 和 i3 的工作区和桌面面板 符合 EWMH 窗口管理器的工作区模块 键盘布局和指示灯状态 CPU 和内存负载指示器 电池电量 网络连接详细信息 日期和时间 用户自定义的菜单树...
项目地址:
https://github.com/polybar/polybar
安装使用
安装
Debian
sudo apt -t bullseye-backports install polybar
Ubuntu 20.10 或以上
sudo apt install polybar
Arch Linux 或 Manjaro
sudo pacman -S polybar
Void Linux
xbps-install -S polybar
NixOS
nix-env -iA nixos.polybar
Source Mage GNU/Linux
cast polybar
openSUSE Leap 或 openSUSE Tumbleweed
zypper install polybar
FreeBSD
pkg install polybar
Fedora
sudo dnf install polybar
运行
正常安装的情况下,polybar 会将默认配置文件放到 /etc/polybar/config.ini。只需在终端中执行以下命令,该配置文件就可以开箱即用:
polybar
如果需要开启个性化配置,只需要创建 ~/.config/polybar/config.ini 文件,模仿默认的配置文件进行编写即可。
polybar 启动的相关命令行参数:
-h, --help 显示帮助信息
-v, --version 显示构建信息、版本号
-l, --log=LEVEL 设置日志级别 (默认: notice)
允许设置的级别: error, warning, notice, info, trace
-q, --quiet 静默启动
-c, --config=FILE 指定配置文件路径
-r, --reload 重新加载配置文件
-m, --list-monitors 打印可用的监控器列表(不包括克隆监控器)
-M, --list-all-monitors 打印全部监控器列表(包括克隆监控器)
-w, --print-wmname 打印 wmname
-s, --stdout 数据输出到标准输出
-p, --png=FILE 运行 3 秒后保存 png 截图文件
配置
polybar 配置文件定义了 polybar 的行为和外观。它使用 INI 文件格式,启动时 polybar 将按以下顺序在多个文职搜索配置文件:
如果指定了 -cor--config 参数,那就使用这个参数指定的路径。 $XDG_CONFIG_HOME/polybar/config $XDG_CONFIG_HOME/polybar/config.ini $HOME/.config/polybar/config $HOME/.config/polybar/config.ini $XDG_CONFIG_DIRS/polybar/config.ini /etc/xdg/polybar/config.ini(仅当XDG_CONFIG_DIRS未设置时) /etc/polybar/config.ini
栏设置
polybar 中每个服务的状态栏都是在配置文件中的配置的,以 bar/ 开头,紧跟着的是状态栏的名字:
;==========================================================
;
;
; ██████╗ ██████╗ ██╗ ██╗ ██╗██████╗ █████╗ ██████╗
; ██╔══██╗██╔═══██╗██║ ╚██╗ ██╔╝██╔══██╗██╔══██╗██╔══██╗
; ██████╔╝██║ ██║██║ ╚████╔╝ ██████╔╝███████║██████╔╝
; ██╔═══╝ ██║ ██║██║ ╚██╔╝ ██╔══██╗██╔══██║██╔══██╗
; ██║ ╚██████╔╝███████╗██║ ██████╔╝██║ ██║██║ ██║
; ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝
;
;
; To learn more about how to configure Polybar
; go to https://github.com/polybar/polybar
;
; The README contains a lot of information
;
;==========================================================
[colors]
background = #282A2E
background-alt = #373B41
foreground = #C5C8C6
primary = #F0C674
secondary = #8ABEB7
alert = #A54242
disabled = #707880
[bar/example]
width = 100%
height = 24pt
radius = 6
; dpi = 96
background = ${colors.background}
foreground = ${colors.foreground}
line-size = 3pt
border-size = 4pt
border-color = #00000000
padding-left = 0
padding-right = 1
module-margin = 1
separator = |
separator-foreground = ${colors.disabled}
font-0 = monospace;2
modules-left = xworkspaces xwindow
modules-right = filesystem pulseaudio xkeyboard memory cpu wlan eth date
cursor-click = pointer
cursor-scroll = ns-resize
enable-ipc = true
; tray-position = right
; wm-restack = generic
; wm-restack = bspwm
; wm-restack = i3
; override-redirect = true
[module/xworkspaces]
type = internal/xworkspaces
label-active = %name%
label-active-background = ${colors.background-alt}
label-active-underline= ${colors.primary}
label-active-padding = 1
label-occupied = %name%
label-occupied-padding = 1
label-urgent = %name%
label-urgent-background = ${colors.alert}
label-urgent-padding = 1
label-empty = %name%
label-empty-foreground = ${colors.disabled}
label-empty-padding = 1
[module/xwindow]
type = internal/xwindow
label = %title:0:60:...%
[module/filesystem]
type = internal/fs
interval = 25
mount-0 = /
label-mounted = %{F#F0C674}%mountpoint%%{F-} %percentage_used%%
label-unmounted = %mountpoint% not mounted
label-unmounted-foreground = ${colors.disabled}
[module/pulseaudio]
type = internal/pulseaudio
format-volume-prefix = "VOL "
format-volume-prefix-foreground = ${colors.primary}
format-volume = <label-volume>
label-volume = %percentage%%
label-muted = muted
label-muted-foreground = ${colors.disabled}
[module/xkeyboard]
type = internal/xkeyboard
blacklist-0 = num lock
label-layout = %layout%
label-layout-foreground = ${colors.primary}
label-indicator-padding = 2
label-indicator-margin = 1
label-indicator-foreground = ${colors.background}
label-indicator-background = ${colors.secondary}
[module/memory]
type = internal/memory
interval = 2
format-prefix = "RAM "
format-prefix-foreground = ${colors.primary}
label = %percentage_used:2%%
[module/cpu]
type = internal/cpu
interval = 2
format-prefix = "CPU "
format-prefix-foreground = ${colors.primary}
label = %percentage:2%%
[network-base]
type = internal/network
interval = 5
format-connected = <label-connected>
format-disconnected = <label-disconnected>
label-disconnected = %{F#F0C674}%ifname%%{F#707880} disconnected
[module/wlan]
inherit = network-base
interface-type = wireless
label-connected = %{F#F0C674}%ifname%%{F-} %essid% %local_ip%
[module/eth]
inherit = network-base
interface-type = wired
label-connected = %{F#F0C674}%ifname%%{F-} %local_ip%
[module/date]
type = internal/date
interval = 1
date = %H:%M
date-alt = %Y-%m-%d %H:%M:%S
label = %date%
label-foreground = ${colors.primary}
[settings]
screenchange-reload = true
pseudo-transparency = true
; vim:ft=dosini
- EOF -
加主页君微信,不仅Linux技能+1
主页君日常还会在个人微信分享Linux相关工具、资源和精选技术文章,不定期分享一些有意思的活动、岗位内推以及如何用技术做业余项目
加个微信,打开一扇窗
看完本文有收获?请分享给更多人
推荐关注「Linux 爱好者」,提升Linux技能
点赞和在看就是最大的支持❤️