feat: bookmarks

This commit is contained in:
ange 2025-02-17 06:08:25 +00:00
parent ddd00d7844
commit 98ec0130fd
Signed by: ange
GPG key ID: 9E0C4157BB7BEB1D
19 changed files with 223 additions and 90 deletions

View file

@ -32,8 +32,8 @@ function update_bat() {
function update_sink_vol() {
local vol mute
read -r vol mute < <(wpctl get-volume '@DEFAULT_AUDIO_SINK@')
vol="$((10#${vol/./}))"
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"
@ -44,8 +44,8 @@ function update_sink_vol() {
function update_source_vol() {
local vol mute
read -r vol mute < <(wpctl get-volume '@DEFAULT_AUDIO_SOURCE@')
vol="$((10#${vol/./}))"
read -r _ vol mute < <(wpctl get-volume '@DEFAULT_AUDIO_SOURCE@') || return
vol=$((10#${vol/./}))
if [ -n "$mute" ]; then source_vol='🔇'
else source_vol=" $vol"
fi
@ -76,6 +76,14 @@ function update_net() {
esac
}
function update_vpn() {
local v; v="$(ip -br link show type wireguard | awk '{print $1}')"
if [ -n "$v" ]; then vpn=" 🔒 $v"
else vpn=
fi
}
function update_time() {
time="$(TZ=Asia/Makassar date '+%R %Z') - $(date -u '+%a %m-%d %R')"
}
@ -85,7 +93,7 @@ function reload() {
}
function display() {
"${DISPLAYCMD[@]}" "$crypto | $cpu | $memory | $sink_vol $source_vol | $net | $bat | $time"
"${DISPLAYCMD[@]}" "$crypto | $cpu | $memory | $sink_vol $source_vol | $net$vpn | $bat | $time"
}
if [ "$XDG_SESSION_TYPE" = wayland ]; then
@ -100,26 +108,29 @@ 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'
# to update it from external commands
## kill -m "$(cat ~/.cache/pidofbar)"
## kill -m "$(cat "$XDG_CACHE_HOME/pidofbar")"
# where m = 34 + n
echo "$$" > "$HOME/.cache/pidofbar"
echo "$$" > "$XDG_CACHE_HOME/pidofbar"
sec=0
while true; do
[ "$((sec % 300))" -eq 5 ] && update_crypto
[ "$((sec % 5))" -eq 0 ] && {
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))
awk "@load \"time\"; BEGIN {d=5; s=$(date '+%S.%N'); sleep(d - s % d)}" &
wait
sleep $((5 - 10#$(date '+%S') % 5)) & wait
done