Skip to content

Commit

Permalink
feat(polybar): add secondary-stats bar
Browse files Browse the repository at this point in the history
With CPU and RAM usage bars.
  • Loading branch information
eliasnorrby committed Jul 6, 2021
1 parent d9bdff4 commit ac545c3
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 8 deletions.
43 changes: 42 additions & 1 deletion panel/polybar/config
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ modules-left = bspwm
modules-center =
modules-right =

[bar/secondary-stats]
inherit = bar/secondary

modules-center = memory-bar cpu-bar

[module/vpn]
type = custom/script
exec = if pgrep -x openfortivpn >/dev/null; then echo " "; else echo " "; fi
Expand Down Expand Up @@ -145,12 +150,48 @@ format-prefix = " "
format-prefix-foreground = ${colors.foreground-alt}
label = %percentage:2%%

[module/cpu-bar]
type = internal/cpu
interval = 2
format = <bar-load> <label>
format-prefix = CPU
format-prefix-foreground = ${colors.foreground-alt}
label = %percentage:2%%

bar-load-indicator =
bar-load-width = 50
bar-load-foreground-0 = #55aa55
bar-load-foreground-1 = #557755
bar-load-foreground-2 = #f5a70a
bar-load-foreground-3 = #ff5555
bar-load-fill = ▐
bar-load-empty = ▐
bar-load-empty-foreground = #444444

[module/memory]
type = internal/memory
interval = 2
format-prefix = ""
format-prefix-foreground = ${colors.foreground-alt}
label = %percentage_used%%
label = %percentage_used:2%%

[module/memory-bar]
type = internal/memory
interval = 2
format-prefix = RAM
format = <bar-used> <label>
format-prefix-foreground = ${colors.foreground-alt}
label = %percentage_used:2%%

bar-used-indicator =
bar-used-width = 50
bar-used-foreground-0 = #55aa55
bar-used-foreground-1 = #557755
bar-used-foreground-2 = #f5a70a
bar-used-foreground-3 = #ff5555
bar-used-fill = ▐
bar-used-empty = ▐
bar-used-empty-foreground = #444444

[module/eth]
type = internal/network
Expand Down
40 changes: 33 additions & 7 deletions panel/polybar/launch.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,39 @@
#!/usr/bin/env bash
#!/bin/sh

killall -q polybar

#echo "---" | tee -a /tmp/polybar.log
#polybar mybar >> /tmp/polybar.log 2>&1 & disown
list_monitors() {
polybar --list-monitors
}

pm=$(polybar --list-monitors | grep '(primary)' | cut -d":" -f1)
MONITOR=$pm polybar --reload main &
monitor_name() {
cut -d ":" -f 1
}

for m in $(polybar --list-monitors | grep -v '(primary)' | cut -d":" -f1); do
MONITOR=$m polybar --reload secondary &
exclude_primary() {
grep -v '(primary)'
}

exclude_rightmost() {
if [ -n "$rightmost_monitor" ]; then
grep -v "$rightmost_monitor"
else
cat
fi
}

launch_bar_on_monitor() {
MONITOR=$2 polybar --reload "$1" &
}

primary_monitor=$(list_monitors | grep '(primary)' | monitor_name)
launch_bar_on_monitor main "$primary_monitor"

rightmost_monitor=$(list_monitors | exclude_primary | tail -1 | monitor_name)
if [ -n "$rightmost_monitor" ]; then
launch_bar_on_monitor secondary-stats "$rightmost_monitor"
fi

for monitor in $(list_monitors | exclude_primary | exclude_rightmost | monitor_name); do
launch_bar_on_monitor secondary "$monitor"
done

0 comments on commit ac545c3

Please sign in to comment.