Linux: polybar – примеры polybar-scripts

Автор: | 08/10/2018

На Github имеется коллекция community-скриптов для polybar.

Ниже примеры добавления скриптов для отображения погоды и количества доступных апдейтов на Arch Linux.

Клонируем репозитория со скриптами:

[simterm]

$ cd /home/setevoy/.config/polybar/
$ git clone https://github.com/x70b1/polybar-scripts.git

[/simterm]

openweathermap-forecast

openweathermap-forecast отображает текущую погоду и прогноз изменений через 3 часа.

Для корректного отображения требуются jq и ttf-weather-icons.

Регистририуемся на странице https://home.openweathermap.org/api_keys, получаем API KEY.

Находим город на странице https://openweathermap.org/find, для Киева это будет https://openweathermap.org/city/703448, и его ID == 703448.

Редактируем скрипт polybar-scripts/polybar-scripts/openweathermap-forecast/openweathermap-forecast.sh, задаём переменные:

...
KEY="0ec***13c"
CITY="703448"
UNITS="metric"
SYMBOL="°"
...

KEY – полученный API KEY, в CITYID города.

Задаём chmod:

[simterm]

$ chmod +x ~/.config/polybar/polybar-scripts/polybar-scripts/openweathermap-forecast/openweathermap-forecast.sh

[/simterm]

Устанавливаем шрифт с иконками:

[simterm]

$ yaourt -S ttf-weather-icons

[/simterm]

Проверяем работу скрипта:

[simterm]

$ ./polybar-scripts/polybar-scripts/openweathermap-forecast/openweathermap-forecast.sh
 15°     21°

[/simterm]

Редактируем конфиг polybar, добавляем модуль:

...
modules-left = openweathermap-forecast hostname menu
...
font-7 = Weather Icons:size=12;1
...
[module/openweathermap-forecast]
type = custom/script
exec = ~/.config/polybar/polybar-scripts/polybar-scripts/openweathermap-forecast/openweathermap-forecast.sh
interval = 600
label-font = 8

Запускаем:

updates-arch-combined

Этот скрипт выводит количество доступных обновлений для пакетов из основного репозитория и AUR.

Для получения информации для pacman – используется pacman-contrib, для AUR – yay.

Устанавливаем yay:

[simterm]

$ git clone https://aur.archlinux.org/yay.git
$ cd yay/
$ makepkg -si

[/simterm]

И pacman-contrib:

[simterm]

$ sudo pacman -S pacman-contrib

[/simterm]

Устанавливаем скрипт (если репозиторий ещё не склонирован):

[simterm]

$ cd /home/setevoy/.config/polybar/
$ git clone https://github.com/x70b1/polybar-scripts.git
$ chmod +x ~/.config/polybar/polybar-scripts/polybar-scripts/updates-arch-combined/updates-arch-combined.sh

[/simterm]

Проверяем его работу:

[simterm]

$ ~/.config/polybar/polybar-scripts/polybar-scripts/updates-arch-combined/updates-arch-combined.sh
# 61

[/simterm]

Можно отредактировать скрипт, и вместо # установить свою иконку, например sync из коллекции https://fontawesome.com/cheatsheet.

Добавляем модуль в конфиг polybar и его вызов в bar:

...
[bar/top]
inherit = bar/base

width = 100%
height = 24

modules-right = cpu memory filesystem wlan volume temperature battery date
modules-left = hostname updates-arch-combined menu openweathermap-forecast
...
[module/updates-arch-combined]
type = custom/script
exec = /home/setevoy/.config/polybar/polybar-scripts/polybar-scripts/updates-arch-combined/updates-arch-combined.sh
interval = 600

Запускаем, проверяем:

Готово.