From 5f41530745cc93b6b63f0973005bad6030bd5dae Mon Sep 17 00:00:00 2001 From: marc Date: Sun, 6 Nov 2022 23:43:43 +0100 Subject: [PATCH] Further polybar customization --- config/.config/polybar/bars/bars.ini | 11 ++++++-- config/.config/polybar/bars/colours.ini | 14 ++++++++++ .../polybar/bars/modules/bluetooth.ini | 4 +-- .../.config/polybar/bars/modules/padding.ini | 13 --------- .../.config/polybar/bars/modules/spotify.ini | 8 ++++++ .../.config/polybar/bars/modules/wireless.ini | 28 +++++++++++++++++++ .../polybar/{bars => }/scripts/bluetooth.sh | 3 +- config/.config/polybar/scripts/spotify.sh | 20 +++++++++++++ home/modules/desktop/polybar.nix | 3 +- 9 files changed, 84 insertions(+), 20 deletions(-) delete mode 100644 config/.config/polybar/bars/modules/padding.ini create mode 100644 config/.config/polybar/bars/modules/spotify.ini create mode 100644 config/.config/polybar/bars/modules/wireless.ini rename config/.config/polybar/{bars => }/scripts/bluetooth.sh (98%) create mode 100755 config/.config/polybar/scripts/spotify.sh diff --git a/config/.config/polybar/bars/bars.ini b/config/.config/polybar/bars/bars.ini index f8e8cee..fc6d713 100644 --- a/config/.config/polybar/bars/bars.ini +++ b/config/.config/polybar/bars/bars.ini @@ -32,12 +32,17 @@ padding-left = 0 padding-right = 0 module-margin-left = 0 +separator = | +separator-padding = .5 +separator-foreground = ${colours.trans} +separator-background = ${colours.trans} + [bar/bottom] inherit = bar/base bottom = true modules-left = workspaces -modules-right = bluetooth paddinglite volume paddinglite battery +modules-right = wireless bluetooth volume battery tray-position = center tray-maxsize = 28 @@ -46,6 +51,6 @@ tray-maxsize = 28 inherit = bar/base bottom = false -modules-left = +modules-left = spotify modules-center = date -modules-right = i3-mode +modules-right = i3-mode diff --git a/config/.config/polybar/bars/colours.ini b/config/.config/polybar/bars/colours.ini index dd9adb1..da81667 100644 --- a/config/.config/polybar/bars/colours.ini +++ b/config/.config/polybar/bars/colours.ini @@ -28,6 +28,8 @@ orange- = #FEB548 orange = #F18F01 orange+ = #A26201 +apricot = #FFCAB1 + rose- = #CC8FA0 rose = #AB4E68 rose+ = #7E3A4D @@ -64,6 +66,18 @@ volume-fg = ${colours.white} muted-bg = ${colours.rose-} muted-fg = ${colours.white} +[colours/wireless] +connected-bg = ${colours.apricot} +connected-fg = ${colours.gray} +disconnected-bg = ${colours.apricot} +disconnected-fg = ${colours.gray} +packetloss-bg = ${colours.apricot} +packetloss-fg = ${colours.gray} + [colours/bluetooth] bg = ${colours.blue} fg = ${colours.white} + +[colours/spotify] +bg = ${colours.green} +fg = ${colours.gray} diff --git a/config/.config/polybar/bars/modules/bluetooth.ini b/config/.config/polybar/bars/modules/bluetooth.ini index 1d9e982..6904f03 100644 --- a/config/.config/polybar/bars/modules/bluetooth.ini +++ b/config/.config/polybar/bars/modules/bluetooth.ini @@ -1,8 +1,8 @@ [module/bluetooth] type = custom/script -exec = scripts/bluetooth.sh +exec = ~/.config/polybar/scripts/bluetooth.sh interval = 5 -click-left = scripts/bluetooth.sh --toggle & +click-left = ~/.config/polybar/scripts/bluetooth.sh --toggle & format-background = ${colours/bluetooth.bg} format-foreground = ${colours/bluetooth.fg} diff --git a/config/.config/polybar/bars/modules/padding.ini b/config/.config/polybar/bars/modules/padding.ini deleted file mode 100644 index 628207f..0000000 --- a/config/.config/polybar/bars/modules/padding.ini +++ /dev/null @@ -1,13 +0,0 @@ -[module/padding] -type = custom/text -content = || -content-padding = 1 -content-foreground = ${colours.trans} -content-background = ${colours.trans} - -[module/paddinglite] -type = custom/text -content = | -content-padding = .5 -content-foreground = ${colours.trans} -content-background = ${colours.trans} diff --git a/config/.config/polybar/bars/modules/spotify.ini b/config/.config/polybar/bars/modules/spotify.ini new file mode 100644 index 0000000..e8d6a2c --- /dev/null +++ b/config/.config/polybar/bars/modules/spotify.ini @@ -0,0 +1,8 @@ +[module/spotify] +type = custom/script +exec = ~/.config/polybar/scripts/spotify.sh +interval = 5 + +format-background = ${colours/spotify.bg} +format-foreground = ${colours/spotify.fg} +format-padding = 1 diff --git a/config/.config/polybar/bars/modules/wireless.ini b/config/.config/polybar/bars/modules/wireless.ini new file mode 100644 index 0000000..5f181cb --- /dev/null +++ b/config/.config/polybar/bars/modules/wireless.ini @@ -0,0 +1,28 @@ +[module/wireless] +type = internal/network +interface-type = wireless +interval = 3.0 + +accumulate-stats = true +;unknown-as-up = true + +; The unit used for displaying network speeds +; For example if set to the empty string, a speed of 5 KB/s is displayed as 5 K +speed-unit = '' + +format-connected = +label-connected = %essid% (%local_ip%) +label-connected-background = ${colours/wireless.connected-bg} +label-connected-foreground = ${colours/wireless.connected-fg} +label-connected-padding = 1 + +format-disconnected = +label-disconnected = not connected +label-disconnected-background = ${colours/wireless.disconnected-bg} +label-disconnected-foreground = ${colours/wireless.disconnected-fg} +label-disconnected-padding = 1 + +format-packetloss = * +label-packetloss-background = ${colours/wireless.packetloss-bg} +label-packetloss-foreground = ${colours/wireless.packetloss-fg} +label-packetloss-padding = 1 diff --git a/config/.config/polybar/bars/scripts/bluetooth.sh b/config/.config/polybar/scripts/bluetooth.sh similarity index 98% rename from config/.config/polybar/bars/scripts/bluetooth.sh rename to config/.config/polybar/scripts/bluetooth.sh index 34936b4..491cd72 100755 --- a/config/.config/polybar/bars/scripts/bluetooth.sh +++ b/config/.config/polybar/scripts/bluetooth.sh @@ -25,7 +25,8 @@ bluetooth_print() { printf '\n' else - echo "" + # "" + echo "" fi } diff --git a/config/.config/polybar/scripts/spotify.sh b/config/.config/polybar/scripts/spotify.sh new file mode 100755 index 0000000..5f1d366 --- /dev/null +++ b/config/.config/polybar/scripts/spotify.sh @@ -0,0 +1,20 @@ +#!/bin/sh + +main() { + pgrep spotify -l | grep -v spotify.sh > /dev/null || return + + cmd="org.freedesktop.DBus.Properties.Get" + domain="org.mpris.MediaPlayer2" + path="/org/mpris/MediaPlayer2" + + meta=$(dbus-send --print-reply --dest=${domain}.spotify /org/mpris/MediaPlayer2 ${cmd} string:${domain}.Player string:Metadata) + + # Normal track + artist=$(echo "$meta" | sed -nr '/xesam:artist"/,+2s/^ +string "(.*)"$/\1/p' | tail -1 | sed 's/\&/\\&/g' | sed 's#\/#\\/#g') + album=$(echo "$meta" | sed -nr '/xesam:album"/,+2s/^ +variant +string "(.*)"$/\1/p' | tail -1| sed 's/\&/\\&/g'| sed 's#\/#\\/#g') + title=$(echo "$meta" | sed -nr '/xesam:title"/,+2s/^ +variant +string "(.*)"$/\1/p' | tail -1 | sed 's/\&/\\&/g'| sed 's#\/#\\/#g') + + echo "阮 ${*:-%artist% - %title%}" | sed "s/%artist%/$artist/g;s/%title%/$title/g;s/%album%/$album/g"i | sed "s/\&/\&/g" | sed "s#\/#\/#g" +} + +main "$@" diff --git a/home/modules/desktop/polybar.nix b/home/modules/desktop/polybar.nix index fcc6997..252d9e7 100644 --- a/home/modules/desktop/polybar.nix +++ b/home/modules/desktop/polybar.nix @@ -26,6 +26,7 @@ in { xdg.configFile."polybar/config.ini".source = ../../../config/.config/polybar/config.ini; xdg.configFile."polybar/bars".source = ../../../config/.config/polybar/bars; + xdg.configFile."polybar/scripts".source = ../../../config/.config/polybar/scripts; systemd.user.services.polybar = { Unit = { @@ -36,7 +37,7 @@ in { Service = { Type = "forking"; - Environment = "PATH=${polybar_pkg}/bin:/run/wrappers/bin"; + PassEnvironment = "PATH"; ExecStart = let scriptPkg = pkgs.writeShellScriptBin "polybar-start" script; in "${scriptPkg}/bin/polybar-start";