From 960573ae4efdf3048a92b6960e84526f953b64cc Mon Sep 17 00:00:00 2001 From: Daniel Carrillo Date: Sat, 15 Jun 2024 21:21:20 +0200 Subject: [PATCH] [polybar] Add Syncthing status and improve output icon sizes --- .config/nvim/lua/core/lazy.lua | 2 +- .config/polybar/bar.ini | 4 ++-- .config/polybar/launch.sh | 2 +- .config/polybar/modules.ini | 13 ++++++++++--- .config/polybar/scripts/check_updates | 2 +- .config/polybar/scripts/check_vpn | 16 ++++++++++------ .config/polybar/scripts/network_status | 4 ++-- .config/polybar/scripts/network_usage | 6 +++--- .config/polybar/scripts/syncthing_status | 19 +++++++++++++++++++ 9 files changed, 49 insertions(+), 19 deletions(-) create mode 100755 .config/polybar/scripts/syncthing_status diff --git a/.config/nvim/lua/core/lazy.lua b/.config/nvim/lua/core/lazy.lua index 55de354..637a577 100644 --- a/.config/nvim/lua/core/lazy.lua +++ b/.config/nvim/lua/core/lazy.lua @@ -1,5 +1,5 @@ local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" -if not vim.loop.fs_stat(lazypath) then +if not (vim.uv or vim.loop).fs_stat(lazypath) then vim.fn.system({ "git", "clone", diff --git a/.config/polybar/bar.ini b/.config/polybar/bar.ini index dce85da..58418b0 100644 --- a/.config/polybar/bar.ini +++ b/.config/polybar/bar.ini @@ -53,7 +53,7 @@ foreground = ${colors.foreground} ; https://www.nerdfonts.com/cheat-sheet font-0 = "RobotoMono Nerd Font Mono:style=Regular:size=16:antialias=true;4" ; https://fontawesome.com/cheatsheet/free -font-1 = "FontAwesome:size=16:antialias=true;2" +font-1 = "FontAwesome:size=16:antialias=true;4" font-2 = "Material Icons:size=16:antialias=true;1" font-3 = "NotoSans-Regular:size=18:weight=bold:antialias=true;6" font-4 = "NotoSans-Regular:size=28:weight=bold:antialias=true;-11 @@ -62,7 +62,7 @@ font-6 = "Font Awesome 6 Brands-Regular-400:size=32:antialias=true;1" modules-left = polywins modules-center = custom_date -modules-right = updates cpu_bar memory_bar docker vpn network_status network_usage alsa_bar tray +modules-right = updates cpu_bar memory_bar docker vpn network_status network_usage syncthing_status alsa_bar tray cursor-click = pointer cursor-scroll = ns-resize diff --git a/.config/polybar/launch.sh b/.config/polybar/launch.sh index a39d9f1..b0f1d88 100755 --- a/.config/polybar/launch.sh +++ b/.config/polybar/launch.sh @@ -15,7 +15,7 @@ function wait_for_polybar fi while [ "$(pgrep -u "$(id -u)" -x polybar >/dev/null)" = $condition ]; do - sleep 0.2 + sleep 1 done } diff --git a/.config/polybar/modules.ini b/.config/polybar/modules.ini index 993d629..2628faf 100644 --- a/.config/polybar/modules.ini +++ b/.config/polybar/modules.ini @@ -27,7 +27,7 @@ interval = 5 [module/memory_bar] type = internal/memory format = -format-prefix = "%{A1:$TERMINAL_CMD top -o RES &:} %{A}" +format-prefix = "%{A1:$TERMINAL_CMD top -o RES &:}%{T2} %{T-}%{A}" format-prefix-foreground = ${colors.foreground-alt} bar-used-width = 10 @@ -120,7 +120,7 @@ click-left = gnome-calendar type = internal/alsa format-volume = -label-volume = "%{A3:$TERMINAL_CMD pulsemixer &:}%{A}" +label-volume = "%{A3:$TERMINAL_CMD pulsemixer &:}%{T4}%{T-}%{A}" label-volume-foreground = ${root.foreground} format-muted-prefix = "" @@ -161,6 +161,13 @@ label = "%output%" label-padding = 0 tail = true +[module/syncthing_status] +type = custom/script +exec = ~/.config/polybar/scripts/syncthing_status +interval = 10 +exec-if = syncthing cli show system > /dev/null +click-left = $BROWSER_CMD $(syncthing cli show system | jq -r .guiAddressUsed) + [module/battery] type = internal/battery @@ -179,7 +186,7 @@ type = custom/script exec = ~/.config/polybar/scripts/docker exec-if = docker ps -q interval = 10 -label = "%output%" +label = "%{T2}%{T-}%output%" [module/tray] type = internal/tray diff --git a/.config/polybar/scripts/check_updates b/.config/polybar/scripts/check_updates index 07e0469..ce7f96e 100755 --- a/.config/polybar/scripts/check_updates +++ b/.config/polybar/scripts/check_updates @@ -3,6 +3,6 @@ while true; do UPDATES=$(checkupdates 2>/dev/null | wc -l) - [ "$UPDATES" -gt 0 ] && echo " $UPDATES" && sleep 30 + [ "$UPDATES" -gt 0 ] && echo "%{T2} %{T-}$UPDATES" && sleep 30 [ "$UPDATES" -eq 0 ] && echo "" && sleep 300 done diff --git a/.config/polybar/scripts/check_vpn b/.config/polybar/scripts/check_vpn index 6f378a8..71ad466 100755 --- a/.config/polybar/scripts/check_vpn +++ b/.config/polybar/scripts/check_vpn @@ -1,11 +1,15 @@ #!/usr/bin/env bash -OUTPUT="" +openvpn_icon="%{T2}%{T-}" +globalprotect_icon="%{T2}%{T-}" -openvpn=$(pgrep -c openvpn$) -[ "$openvpn" -gt 0 ] && OUTPUT=$(eval printf "%.0s" "{1..$openvpn}") +output="" +if pgrep openvpn >/dev/null; then + output=${openvpn_icon} +fi -globalprotect=$(pgrep -c gpclient$) -[ "$globalprotect" -gt 0 ] && OUTPUT=${OUTPUT}$(eval printf '%.0s' "{1..$globalprotect}") +if pgrep gpclient >/dev/null; then + output="${output} ${globalprotect_icon}" +fi -echo "$OUTPUT" | sed -e 's/\(.\)/\1 /g' +echo "$output" diff --git a/.config/polybar/scripts/network_status b/.config/polybar/scripts/network_status index d975a6e..20d1c60 100755 --- a/.config/polybar/scripts/network_status +++ b/.config/polybar/scripts/network_status @@ -3,7 +3,7 @@ URL=${1:-1.0.0.1} output=$(fping --quiet --outage --count=5 "$URL" 2>&1) -outage_output=" " +outage_output="" outage_color="FFFFFF" avg_output="" avg_color="FFFFFF" @@ -28,7 +28,7 @@ else fi if [ -n "$outage_output" ] || [ -n "$avg_output" ]; then - echo "%{F#$outage_color}%{T5}${outage_output}%{F-}%{T-}%{F#$avg_color}%{T5} ${avg_output}%{F-}%{T-}" + echo "%{F#$outage_color}%{T2}${outage_output}%{F-}%{T-}%{F#$avg_color}%{T2} ${avg_output}%{F-}%{T-}" else echo "" fi diff --git a/.config/polybar/scripts/network_usage b/.config/polybar/scripts/network_usage index 025e734..f7a0a04 100755 --- a/.config/polybar/scripts/network_usage +++ b/.config/polybar/scripts/network_usage @@ -22,7 +22,7 @@ get_icon_by_device() ;; esac - echo $icon + echo "$icon" } while true; do @@ -58,9 +58,9 @@ while true; do output=" 0.01 0.01" fi - echo "$icon$output" + echo "%{T2}$icon%{T-}$output" else - echo "$icon-- --" + echo "%{T2}$icon%{T-} -- --" fi echo "$current_values">$COUNTER_FILE diff --git a/.config/polybar/scripts/syncthing_status b/.config/polybar/scripts/syncthing_status new file mode 100755 index 0000000..4367611 --- /dev/null +++ b/.config/polybar/scripts/syncthing_status @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +output="" +while IFS="[ .]" read -r connected paused; do + if [ "$paused" == "true" ]; then + output="${output} " + continue + fi + + if [ "$connected" == "false" ]; then + output="${output}󰅤 " + else + output="${output} " + fi +done <<-EOF + $(syncthing cli show connections | jq -r '.connections[] | "\(.connected) \(.paused)"') +EOF + +printf "%s" "%{T2}${output%?}%{T-}"