From 2fe354a1bdf9b8dce756c0751d766100ec2455b2 Mon Sep 17 00:00:00 2001 From: Vlad Date: Sun, 11 Jan 2026 00:00:21 +0300 Subject: [PATCH] refactored batteries script, tscale_native uses core utils instead of rg and jq --- bin/batteries | 11 ++++++++- i3/.config/i3/config | 3 ++- i3/.config/i3blocks/config | 6 ++++- i3/.config/i3blocks/tscale_native | 37 +++++++++++++++++++++++++++++++ i3/.config/i3blocks/workvpn | 20 +++++++++++++++++ 5 files changed, 74 insertions(+), 3 deletions(-) create mode 100755 i3/.config/i3blocks/tscale_native create mode 100755 i3/.config/i3blocks/workvpn diff --git a/bin/batteries b/bin/batteries index 79ca96a..16653f4 100755 --- a/bin/batteries +++ b/bin/batteries @@ -38,6 +38,8 @@ batteries=$(acpi | rg 'Battery (\d)' -or '$1') # echo "BATTERIES: $batteries" text="" +ischarging=0 +hasenough=0 for battery in $batteries; do # echo "BATTERY $battery" bt=$(acpi -b | grep "Battery $battery") @@ -45,11 +47,18 @@ for battery in $batteries; do STAT=$(echo "$bt" | rg ": ([\w\s]+)," -or '$1') ICON=$(geticon "$BAT" "$STAT") COLOR=$(getcolor "$BAT" "$STAT") - BATTEXT="$ICON $BAT%%" + BATTEXT="$ICON$BAT%%" text+="${BATTEXT} " + + [ "$STAT" = "Charging" ] && ischarging=1 + [ "$BAT" -gt 10 ] hasenough=1 done printf "${text:0:-1}\n\n" +if [ "$hasenough" -eq 0 ] && [ "$ischarging" -eq 0 ]; then + notify-send "Battery level critical" "Please connect AC" +fi + # bt=$(acpi -b | grep "Battery $1") # BAT=$(echo "$bt" | rg "(\d?\d?\d)%" -or '$1') # STAT=$(echo "$bt" | rg ": ([\w\s]+)," -or '$1') diff --git a/i3/.config/i3/config b/i3/.config/i3/config index a28c557..0626197 100644 --- a/i3/.config/i3/config +++ b/i3/.config/i3/config @@ -36,6 +36,7 @@ gaps outer 10 # Start XDG autostart .desktop files using dex. See also # https://wiki.archlinux.org/index.php/XDG_Autostart exec --no-startup-id dex --autostart --environment i3 +exec --no-startup-id pipewire # The combination of xss-lock, nm-applet and pactl is a popular choice, so # they are included here as an example. Modify as you see fit. @@ -71,7 +72,7 @@ floating_modifier $mod tiling_drag modifier # start a terminal -bindsym $mod+Return exec kitty +bindsym $mod+Return exec alacritty # kill focused window bindsym $mod+Shift+q kill diff --git a/i3/.config/i3blocks/config b/i3/.config/i3blocks/config index 7ef0987..7382397 100644 --- a/i3/.config/i3blocks/config +++ b/i3/.config/i3blocks/config @@ -27,7 +27,11 @@ markup=pango #interval=1 [tailscale] -command=~/.config/i3blocks/tscale #echo TS: $(ip a show tailscale0 | rg "inet (\d+\.\d+\.\d+\.\d+)" -or '$1') +command=~/.config/i3blocks/tscale_native #echo TS: $(ip a show tailscale0 | rg "inet (\d+\.\d+\.\d+\.\d+)" -or '$1') +interval=5 + +[workvpn] +command=~/.config/i3blocks/workvpn interval=5 [wthr] diff --git a/i3/.config/i3blocks/tscale_native b/i3/.config/i3blocks/tscale_native new file mode 100755 index 0000000..b39274d --- /dev/null +++ b/i3/.config/i3blocks/tscale_native @@ -0,0 +1,37 @@ +#!/bin/bash + +case $BLOCK_BUTTON in + 1) ~/.dotfiles/bin/rofi-tscale ;; +esac + +icon="󰛳" + +if ! ip a show tailscale0 &>/dev/null; then + icon="󰅛" + out="$icon no tailscale" + which tailscale &>/dev/null && out="$icon tailscale inactive" + echo -e "$out\n$out\n#606060" + exit +fi + +exitnode=$(tailscale status --json | awk '/"ExitNodeStatus": /,/}/') +enstatus="" +tsip=$(ip a show tailscale0 | grep -Po 'inet \K((\d+\.){3}\d+)') +[ -z "$exitnode" ] && { + [ -z "$tsip" ] && { + icon="󰅛" + text="$icon offline" + color='#707070' + } || { + text="$icon $tsip" + COLOR='#8080ff' + } +} || { + enstatus=$(echo "$exitnode" | awk '/TailscaleIPs/,/]/' | grep -Po "(\d+\.){3}\d+") + icon="󰱓" + text="$icon $enstatus" + COLOR='#80ff80' +} +echo "$text" +echo "$text" +echo $COLOR diff --git a/i3/.config/i3blocks/workvpn b/i3/.config/i3blocks/workvpn new file mode 100755 index 0000000..08771c9 --- /dev/null +++ b/i3/.config/i3blocks/workvpn @@ -0,0 +1,20 @@ +#!/usr/bin/env bash + +status=$(ip a show ppp1 2>/dev/null || "") +[ -z "$status" ] && exit 0 + +icon=󱁤 +color="#808080" +text="" +ip=$(grep -Po 'inet \K(\d+\.){3}\d+' <<<$status) +if [ -z "$ip" ]; then + text="$icon wait..." + color="#ffff00" +else + text="$icon $ip" + color="#80ff80" +fi + +echo "$text" +echo "$text" +echo "$color"