feat: massive cleanup, kctx cache

This commit is contained in:
ange 2025-04-05 06:31:22 +00:00
parent 23d1e06c20
commit a759ac8dd2
Signed by: ange
GPG key ID: 9E0C4157BB7BEB1D
28 changed files with 320 additions and 1743 deletions

View file

@ -1,20 +0,0 @@
#!/bin/bash -e
while true; do
mapfile -t LSBLK < <(lsblk -n --paths --list | grep part)
COLUMNS=1
select dev in "${LSBLK[@]}"; do
if [ -z "$dev" ]; then
break
fi
name="$(awk '{print $1}' <<< "$dev")"
if mount | grep -q "$name"; then
umount "$name"
else
udisksctl mount -b "$name" > /dev/null
fi
break
done || exit
done

View file

@ -1,5 +1,4 @@
#!/bin/bash -e
shopt -s extglob
if [ "$1" = -p ]; then

View file

@ -1,5 +1,10 @@
#!/bin/bash -e
if [ -z "$1" ] || [ -z "$2" ]; then
echo "USAGE: $(basename "${BASH_SOURCE[0]}") in out [smallside]" >&2
exit 1
fi
in="$1"; shift
out="$1"; shift
smallside="${1:-720}"; shift || true
@ -9,10 +14,6 @@ if ! [ -r "$in" ]; then
exit 1
fi
if [ -z "$out" ]; then
echo "error: output file name can't be empty" >&2
exit 1
fi
set -x
#ffmpeg -i "$in" -r 24 -vcodec libx265 -vf "scale=-2:$smallside,setpts=0.5*PTS" "$@" "$out"

View file

@ -3,7 +3,6 @@
sites=(
'https://discord.com'
'https://gmoker.com'
'https://linkedin.com'
'https://login.microsoftonline.com'
'https://maby.dev'
'https://web.whatsapp.com'

View file

@ -3,29 +3,24 @@
function update_crypto() {
local c
c="$(crypto 2> /dev/null)" && crypto="$c"
c="$(crypto 2> /dev/null)" && echo "$c" > "$SBAR/crypto"
}
function update_cpu() {
cpu=" $(awk '{print $1}' /proc/loadavg)"
echo " $(awk '{print $1}' /proc/loadavg)" > "$SBAR/cpu"
}
function update_memory() {
memory=" $(free -h | awk '/^Mem:/{print $3}')"
echo " $(free -h | awk '/^Mem:/{print $3}')" > "$SBAR/memory"
}
function update_bat() {
local dir cap
local cap; cap="$(cat /sys/class/power_supply/BAT0/capacity)"
dir='/sys/class/power_supply/BAT0'
cap="$(cat "$dir/capacity")"
if grep -qv Discharging "$dir/status"; then
bat=" $cap%"
elif [ "$cap" -gt 80 ]; then bat=" $cap%"
elif [ "$cap" -gt 60 ]; then bat=" $cap%"
elif [ "$cap" -gt 40 ]; then bat=" $cap%"
elif [ "$cap" -gt 20 ]; then bat=" $cap%"
else bat=" $cap%"
if grep -qv Discharging /sys/class/power_supply/BAT0/status; then
echo " $cap%" > "$SBAR/bat"
else
echo " $cap%" > "$SBAR/bat"
fi
}
@ -33,11 +28,10 @@ function update_sink_vol() {
local vol mute
read -r _ vol mute < <(wpctl get-volume '@DEFAULT_AUDIO_SINK@') || return
vol=$((10#${vol/./}))
if [ -n "$mute" ]; then sink_vol='🔇'
elif [ "$vol" -gt 67 ]; then sink_vol=" $vol"
elif [ "$vol" -gt 33 ]; then sink_vol=" $vol"
else sink_vol=" $vol"
if [ -n "$mute" ]; then
echo '🔇' > "$SBAR/sink"
else
echo " $((10#${vol/./}))" > "$SBAR/sink"
fi
}
@ -45,9 +39,10 @@ function update_source_vol() {
local vol mute
read -r _ vol mute < <(wpctl get-volume '@DEFAULT_AUDIO_SOURCE@') || return
vol=$((10#${vol/./}))
if [ -n "$mute" ]; then source_vol='🔇'
else source_vol=" $vol"
if [ -n "$mute" ]; then
echo '' > "$SBAR/source"
else
echo " $((10#${vol/./}))" > "$SBAR/source"
fi
}
@ -58,20 +53,20 @@ function update_net() {
j="$(networkctl status "$dev" --json=short)"
case "$(jq -r .Type <<< "$j")" in
ether)
net="🌐 $dev"
echo "🌐 $dev" > "$SBAR/net"
;;
wlan)
ssid="$(jq -r .SSID <<< "$j")"
sig="$(awk "/$dev/{printf \"%.0f\", \$3}" /proc/net/wireless)"
if [ "$sig" -gt 56 ]; then net="▂▄▆█ $ssid"
elif [ "$sig" -gt 38 ]; then net="▂▄▆_ $ssid"
elif [ "$sig" -gt 21 ]; then net="▂▄__ $ssid"
elif [ "$sig" -gt 3 ]; then net="▂___ $ssid"
else net="____ $ssid"
if [ "$sig" -gt 56 ]; then echo "▂▄▆█ $ssid" > "$SBAR/net"
elif [ "$sig" -gt 38 ]; then echo "▂▄▆_ $ssid" > "$SBAR/net"
elif [ "$sig" -gt 21 ]; then echo "▂▄__ $ssid" > "$SBAR/net"
elif [ "$sig" -gt 3 ]; then echo "▂___ $ssid" > "$SBAR/net"
else echo "____ $ssid" > "$SBAR/net"
fi
;;
*)
net='⚠'
echo '⚠' > "$SBAR/net"
;;
esac
}
@ -79,58 +74,54 @@ function update_net() {
function update_vpn() {
local v; v="$(ip -br link show type wireguard | awk '{print $1}')"
if [ -n "$v" ]; then vpn=" 🔒 $v"
else vpn=
if [ -n "$v" ]; then
echo " 🔒 $v" > "$SBAR/vpn"
else
: > "$SBAR/vpn"
fi
}
function update_time() {
time="$(TZ=Asia/Makassar date '+%R %Z') - $(date -u '+%a %m-%d %R')"
}
function reload() {
sec=0
echo "$(TZ=Asia/Makassar date '+%R %Z') - $(date -u '+%a %m-%d %R')" \
> "$SBAR/time"
}
function display() {
"${DISPLAYCMD[@]}" "$crypto | $cpu | $memory | $sink_vol $source_vol | $net$vpn | $bat | $time"
for f in "$SBAR"/*; do
local "$(basename "$f")"="$(cat "$f")"
done
# shellcheck disable=SC2154
xsetroot -name "$crypto | $cpu | $memory | $sink $source | $net$vpn | $bat | $time"
}
if [ "$XDG_SESSION_TYPE" = wayland ]; then
DISPLAYCMD=(echo)
else
DISPLAYCMD=(xsetroot -name)
fi
# SIGNALING
# trap '<function>;display;wait' 'RTMIN+n'
trap 'reload' 'RTMIN'
trap 'update_sink_vol;display;wait' 'RTMIN+1'
trap 'update_source_vol;display;wait' 'RTMIN+2'
trap 'update_net;display;wait' 'RTMIN+3'
trap 'update_vpn;display;wait' 'RTMIN+4'
# trap '<function>;display;wait -n' 'RTMIN+n'
trap 'update_sink_vol;display;wait -n' 'RTMIN+0'
trap 'update_source_vol;display;wait -n' 'RTMIN+1'
trap 'update_net;display;wait -n' 'RTMIN+2'
trap 'update_vpn;display;wait -n' 'RTMIN+3'
# to update it from external commands
## kill -m "$(cat "$XDG_CACHE_HOME/pidofbar")"
# where m = 34 + n
echo "$$" > "$XDG_CACHE_HOME/pidofbar"
SBAR="$XDG_CACHE_HOME/sbar"
mkdir -p "$SBAR"
echo "$$" > "$SBAR/pid"
(while :; do
update_crypto
sleep $((300 - 10#$(date '+%S') % 300)) & wait -n
done &)
sec=0
while true; do
if [ $((sec % 300)) -eq 5 ]; then
update_crypto
fi
if [ $((sec % 5)) -eq 0 ]; then
update_cpu
update_memory
update_sink_vol
update_source_vol
update_net
update_vpn
update_bat
update_time
display
fi
((sec += 5))
sleep $((5 - 10#$(date '+%S') % 5)) & wait
update_cpu
update_memory
update_sink_vol
update_source_vol
update_net
update_vpn
update_bat
update_time
display
sleep $((5 - 10#$(date '+%S') % 5)) & wait -n
done

View file

@ -3,11 +3,11 @@
case "$1" in
s)
DEV='@DEFAULT_AUDIO_SINK@'
SIG=35
SIG=34
;;
m)
DEV='@DEFAULT_AUDIO_SOURCE@'
SIG=36
SIG=35
;;
*)
exit 1
@ -33,7 +33,7 @@ function update_vol() {
}
read -r _ CUR MUTE < <(wpctl get-volume "$DEV")
CUR=$(("10#${CUR/./}"))
CUR=$((10#${CUR/./}))
if [ -z "$1" ]; then
echo "$CUR"
@ -49,4 +49,4 @@ else
fi
fi
kill "-$SIG" "$(cat "$XDG_CACHE_HOME/pidofbar")"
kill "-$SIG" "$(cat "$XDG_CACHE_HOME/sbar/pid")"

View file

@ -13,16 +13,15 @@ if [ "$EUID" != 0 ]; then
XDG_CACHE_HOME="$XDG_CACHE_HOME" "$BASH" -- "${BASH_SOURCE[0]}" "$@"
fi
if [ -z "$1" ]; then
set -- "$(basename -s.conf /etc/wireguard/*.conf | "$DMENU")"
if [ "$1" != off ]; then
set -- "$(basename -s.conf "/etc/wireguard/$1"*.conf | "$DMENU")"
if ! wg | grep -q "$1"; then
wg-quick up "$1"
fi
fi
while read -r i; do
wg-quick down "$i"
done < <(wg show interfaces)
done < <(ip -br link show type wireguard | awk "\$1 != \"$1\"{print \$1}")
if [ "$1" != off ]; then
wg-quick up "$1"
fi
kill -38 "$(cat "$XDG_CACHE_HOME/pidofbar")"
kill -37 "$(cat "$XDG_CACHE_HOME/sbar/pid")"

View file

@ -1,6 +1,6 @@
#!/bin/bash -e
iwctl=(iwctl station "$(find /sys/class/net/wlan* -print -quit)")
iwctl=(iwctl station "$(find /sys/class/net/wlan* -printf '%f' -quit)")
rfkill unblock wlan
if ! "${iwctl[@]}" show | grep -q 'Scanning\s\+yes'; then
@ -9,7 +9,7 @@ fi
for _ in {0..29}; do
if "${iwctl[@]}" show | grep -q '\s*State\s\+connected\s*$'; then
kill -37 "$(cat "$XDG_CACHE_HOME/pidofbar")"
kill -36 "$(cat "$XDG_CACHE_HOME/sbar/pid")"
exit 0
fi
sleep 1