From abeb2dcdf2f2e6ca3ed1836d8cf3d6edf93129f3 Mon Sep 17 00:00:00 2001 From: awy Date: Thu, 28 Nov 2024 17:49:11 +0300 Subject: upload --- .local/bin/statusbar/sb-clock | 29 ++++++++++++++++++++ .local/bin/statusbar/sb-doppler | 22 +++++++++++++++ .local/bin/statusbar/sb-forecast | 53 +++++++++++++++++++++++++++++++++++++ .local/bin/statusbar/sb-internet | 43 ++++++++++++++++++++++++++++++ .local/bin/statusbar/sb-mailbox | 20 ++++++++++++++ .local/bin/statusbar/sb-memory | 12 +++++++++ .local/bin/statusbar/sb-microphone | 37 ++++++++++++++++++++++++++ .local/bin/statusbar/sb-nettraf | 29 ++++++++++++++++++++ .local/bin/statusbar/sb-news | 17 ++++++++++++ .local/bin/statusbar/sb-pacpackages | 29 ++++++++++++++++++++ .local/bin/statusbar/sb-popupgrade | 9 +++++++ .local/bin/statusbar/sb-volume | 39 +++++++++++++++++++++++++++ 12 files changed, 339 insertions(+) create mode 100755 .local/bin/statusbar/sb-clock create mode 100755 .local/bin/statusbar/sb-doppler create mode 100755 .local/bin/statusbar/sb-forecast create mode 100755 .local/bin/statusbar/sb-internet create mode 100755 .local/bin/statusbar/sb-mailbox create mode 100755 .local/bin/statusbar/sb-memory create mode 100755 .local/bin/statusbar/sb-microphone create mode 100755 .local/bin/statusbar/sb-nettraf create mode 100755 .local/bin/statusbar/sb-news create mode 100755 .local/bin/statusbar/sb-pacpackages create mode 100755 .local/bin/statusbar/sb-popupgrade create mode 100755 .local/bin/statusbar/sb-volume (limited to '.local/bin/statusbar') diff --git a/.local/bin/statusbar/sb-clock b/.local/bin/statusbar/sb-clock new file mode 100755 index 0000000..56d15d3 --- /dev/null +++ b/.local/bin/statusbar/sb-clock @@ -0,0 +1,29 @@ +#!/bin/sh + +clock=$(date '+%I') + +case "$clock" in + "00") icon="πŸ•›" ;; + "01") icon="πŸ•" ;; + "02") icon="πŸ•‘" ;; + "03") icon="πŸ•’" ;; + "04") icon="πŸ•“" ;; + "05") icon="πŸ•”" ;; + "06") icon="πŸ••" ;; + "07") icon="πŸ•–" ;; + "08") icon="πŸ•—" ;; + "09") icon="πŸ•˜" ;; + "10") icon="πŸ•™" ;; + "11") icon="πŸ•š" ;; + "12") icon="πŸ•›" ;; +esac + +case $BLOCK_BUTTON in + 1) notify-send "This Month" "$(cal | sed "s/\<$(date +'%e'|tr -d ' ')\>/&<\/span><\/b>/")" && notify-send "Appointments" "$(calcurse -d3)" ;; + 2) setsid -f "$TERMINAL" -e calcurse ;; + 3) notify-send "πŸ“… Time/date module" "\- Left click to show upcoming appointments for the next three days via \`calcurse -d3\` and show the month via \`cal\` + - Middle click opens calcurse if installed" ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +date "+%Y %b %d (%a) $icon %H:%M" diff --git a/.local/bin/statusbar/sb-doppler b/.local/bin/statusbar/sb-doppler new file mode 100755 index 0000000..f673fb3 --- /dev/null +++ b/.local/bin/statusbar/sb-doppler @@ -0,0 +1,22 @@ +#!/bin/sh + +# Show a Doppler RADAR of a user's preferred location. +secs=600 # Download a new doppler radar if one hasn't been downloaded in $secs seconds. +radarloc="${XDG_CACHE_HOME:-$HOME/.cache}/radar" +doppler="${XDG_CACHE_HOME:-$HOME/.cache}/doppler.gif" + +getdoppler() { curl -sL https://meteoinfo.ru/hmc-output/rmap/phenomena.gif > "$doppler" ;} + +showdoppler() { setsid -f mpv "$doppler" > /dev/null ;} + +case $BLOCK_BUTTON in + 1) [ $(($(date '+%s') - $(stat -c %Y "$doppler"))) -gt "$secs" ] && getdoppler + showdoppler ;; + 2) getdoppler && showdoppler ;; + 3) notify-send "πŸ—ΊοΈ Doppler RADAR module" "\- Left click for local Doppler RADAR. +- Middle click to update RADAR location. +After $secs seconds, new clicks will also automatically update the doppler RADAR." ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +echo πŸŒ… diff --git a/.local/bin/statusbar/sb-forecast b/.local/bin/statusbar/sb-forecast new file mode 100755 index 0000000..d0e5326 --- /dev/null +++ b/.local/bin/statusbar/sb-forecast @@ -0,0 +1,53 @@ +#!/bin/sh + +# Displays today's precipication chance (β˜”), and daily low (πŸ₯Ά) and high (🌞). +# Usually intended for the statusbar. + +url="${WTTRURL:-wttr.in}" +weatherreport="${XDG_CACHE_HOME:-$HOME/.cache}/weatherreport" + +# Get a weather report from 'wttr.in' and save it locally. +getforecast() { timeout --signal=1 2s curl -sf "$url/$LOCATION" > "$weatherreport" || exit 1; } + +# Forecast should be updated only once a day. +checkforecast() { + [ -s "$weatherreport" ] && [ "$(stat -c %y "$weatherreport" 2>/dev/null | + cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] +} + +getprecipchance() { + echo "$weatherdata" | sed '16q;d' | # Extract line 16 from file + grep -wo "[0-9]*%" | # Find a sequence of digits followed by '%' + sort -rn | # Sort in descending order + head -1q # Extract first line +} + +getdailyhighlow() { + echo "$weatherdata" | sed '13q;d' | # Extract line 13 from file + grep -o "m\\([-+]\\)*[0-9]\\+" | # Find temperatures in the format "m" + sed 's/[+m]//g' | # Remove '+' and 'm' + sort -g | # Sort in ascending order + sed -e 1b -e '$!d' # Extract the first and last lines +} + +readfile() { weatherdata="$(cat "$weatherreport")" ;} + +showweather() { + readfile + printf "rain: %s min: %sΒ° max: %sΒ°\n" "$(getprecipchance)" $(getdailyhighlow) +} + +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e less -Sfr "$weatherreport" ;; + 2) getforecast && showweather ;; + 3) notify-send "🌈 Weather module" "\- Left click for full forecast. +- Middle click to update forecast. +β˜”: Chance of rain/snow +πŸ₯Ά: Daily low +🌞: Daily high" ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +checkforecast || getforecast + +showweather diff --git a/.local/bin/statusbar/sb-internet b/.local/bin/statusbar/sb-internet new file mode 100755 index 0000000..07774e0 --- /dev/null +++ b/.local/bin/statusbar/sb-internet @@ -0,0 +1,43 @@ +#!/bin/sh + +# Show wifi πŸ“Ά and percent strength or πŸ“‘ if none. +# Show 🌐 if connected to ethernet or ❎ if none. +# Show πŸ”’ if a vpn connection is active + +togglevpn() { + if [ ! -n "$(cat /sys/class/net/libre/operstate 2>/dev/null)" ];then + reloadsingbox + notify-send " ο€£ Internet module" "Connected to VPN" + else + killall sing-box + notify-send "  Internet module" "Disconnected from VPN" + fi +} + +case $BLOCK_BUTTON in + 1) togglevpn 2>/dev/null ;; + 3) notify-send "🌐 Internet module" "\- Click to enable/disable VPN + ❌: wifi disabled + πŸ“‘: no wifi connection + πŸ“Ά: wifi connection with quality + ❎: no ethernet + 🌐: ethernet working + πŸ”’: vpn is active + " ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +# Wifi +if [ "$(cat /sys/class/net/w*/operstate 2>/dev/null)" = 'up' ] ; then + wifiicon="$(awk '/^\s*w/ { print "πŸ“Ά", int($3 * 100 / 70) "% " }' /proc/net/wireless)" +elif [ "$(cat /sys/class/net/w*/operstate 2>/dev/null)" = 'down' ] ; then + [ "$(cat /sys/class/net/w*/flags 2>/dev/null)" = '0x1003' ] && wifiicon="πŸ“‘ " || wifiicon="❌ " +fi + +# Ethernet +[ "$(cat /sys/class/net/e*/operstate 2>/dev/null)" = 'up' ] && ethericon="ο›Ώ " || ethericon="❎" + +# Wireguard +[ -n "$(cat /sys/class/net/libre/operstate 2>/dev/null)" ] && tunicon=" ο€£ " + +printf "%s%s%s\n" "$wifiicon" "$ethericon" "$tunicon" diff --git a/.local/bin/statusbar/sb-mailbox b/.local/bin/statusbar/sb-mailbox new file mode 100755 index 0000000..9177e03 --- /dev/null +++ b/.local/bin/statusbar/sb-mailbox @@ -0,0 +1,20 @@ +#!/bin/sh + +# Displays number of unread mail and an loading icon if updating. +# When clicked, brings up `neomutt`. + +case $BLOCK_BUTTON in + 1) setsid -w -f "$TERMINAL" -e neomutt; pkill -RTMIN+12 i3blocks ;; + 2) setsid -f mailsync >/dev/null ;; + 3) notify-send "πŸ“¬ Mail module" "\- Shows unread mail +- Shows πŸ”ƒ if syncing mail +- Left click opens neomutt +- Middle click syncs mail" ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +unread="$(find "${XDG_DATA_HOME:-$HOME/.local/share}"/mail/*/[Ii][Nn][Bb][Oo][Xx]/new/* -type f | wc -l 2>/dev/null)" + +pidof mailsync >/dev/null 2>&1 && icon="ο‹± " + +[ "$unread" = "0" ] && [ "$icon" = "" ] || echo "οƒ  $unread$icon" diff --git a/.local/bin/statusbar/sb-memory b/.local/bin/statusbar/sb-memory new file mode 100755 index 0000000..d95d85c --- /dev/null +++ b/.local/bin/statusbar/sb-memory @@ -0,0 +1,12 @@ +#!/bin/sh + +case $BLOCK_BUTTON in + 1) notify-send "🧠 Memory hogs" "$(ps axch -o cmd:15,%mem --sort=-%mem | head)" ;; + 2) setsid -f "$TERMINAL" -e btop ;; + 3) notify-send "🧠 Memory module" "\- Shows Memory Used/Total. +- Click to show memory hogs. +- Middle click to open htop." ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +free --mebi | sed -n '2{p;q}' | awk '{printf ("ο”Έ %2.2fGiB/%2.2fGiB\n", ( $3 / 1024), ($2 / 1024))}' diff --git a/.local/bin/statusbar/sb-microphone b/.local/bin/statusbar/sb-microphone new file mode 100755 index 0000000..45754c2 --- /dev/null +++ b/.local/bin/statusbar/sb-microphone @@ -0,0 +1,37 @@ +#!/bin/sh + +# Prints the current microphone volume or ο„± if muted. + +case $BLOCK_BUTTON in + 1) setsid -w -f "$TERMINAL" -e pulsemixer; pkill -RTMIN+23 "${STATUSBAR:-i3blocks}" ;; + 2) wpctl set-mute @DEFAULT_SOURCE@ toggle ;; + 4) wpctl set-volume @DEFAULT_SOURCE@ 1%+ ;; + 5) wpctl set-volume @DEFAULT_SOURCE@ 1%- ;; + 3) notify-send "ο„° Microphone volume module" "\- Shows volume ο„°, ο„± if muted. +- Middle click to mute. +- Scroll to change." ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +vol="$(wpctl get-volume @DEFAULT_AUDIO_SOURCE@)" + +# If muted, print ο„± and exit. +[ "$vol" != "${vol%\[MUTED\]}" ] && echo ο„± && exit + +vol="${vol#Volume: }" + +split() { + # For ommiting the . without calling and external program. + IFS=$2 + set -- $1 + printf '%s' "$@" +} + +vol="$(printf "%.0f" "$(split "$vol" ".")")" + +case 1 in + $((vol >= 1)) ) icon="ο„°" ;; + * ) echo ο„± && exit ;; +esac + +echo "$icon $vol%" diff --git a/.local/bin/statusbar/sb-nettraf b/.local/bin/statusbar/sb-nettraf new file mode 100755 index 0000000..2f223d6 --- /dev/null +++ b/.local/bin/statusbar/sb-nettraf @@ -0,0 +1,29 @@ +#!/bin/sh + +# Module showing network traffic. Shows how much data has been received (RX) or +# transmitted (TX) since the previous time this script ran. So if run every +# second, gives network traffic per second. + +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e bmon ;; + 3) notify-send "🌐 Network traffic module" "πŸ”»: Traffic received +πŸ”Ί: Traffic transmitted" ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +update() { + sum=0 + for arg; do + read -r i < "$arg" + sum=$(( sum + i )) + done + cache=/tmp/${1##*/} + [ -f "$cache" ] && read -r old < "$cache" || old=0 + printf %d\\n "$sum" > "$cache" + printf %d\\n $(( sum - old )) +} + +rx=$(update /sys/class/net/[ew]*/statistics/rx_bytes) +tx=$(update /sys/class/net/[ew]*/statistics/tx_bytes) + +printf " %4sB  %4sB\\n" $(numfmt --to=iec $rx $tx) diff --git a/.local/bin/statusbar/sb-news b/.local/bin/statusbar/sb-news new file mode 100755 index 0000000..f5e09fd --- /dev/null +++ b/.local/bin/statusbar/sb-news @@ -0,0 +1,17 @@ +#!/bin/sh + +# Displays number of unread news items and an loading icon if updating. +# When clicked, brings up `newsboat`. + +case $BLOCK_BUTTON in + 1) setsid "$TERMINAL" -e newsboat ;; + 2) setsid -f newsup >/dev/null && exit ;; + 3) notify-send "ο‡ͺ News module" "\- Shows unread news items +- Shows πŸ”ƒ if updating with \`newsup\` +- Left click opens newsboat +- Middle click syncs RSS feeds +Note: Only one instance of newsboat (including updates) may be running at a time." ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + + cat /tmp/newsupdate 2>/dev/null || echo "$(newsboat -x print-unread | awk '{ if($1>0) print "ο‡ͺ " $1}')$(cat "${XDG_CONFIG_HOME:-$HOME/.config}"/newsboat/.update 2>/dev/null)" diff --git a/.local/bin/statusbar/sb-pacpackages b/.local/bin/statusbar/sb-pacpackages new file mode 100755 index 0000000..9b12f34 --- /dev/null +++ b/.local/bin/statusbar/sb-pacpackages @@ -0,0 +1,29 @@ +#!/bin/sh + +# Displays number of upgradeable packages. +# For this to work, have a `pacman -Sy` command run in the background as a +# cronjob every so often as root. This script will then read those packages. +# When clicked, it will run an upgrade via pacman. +# +# Add the following text as a file in /usr/share/libalpm/hooks/statusbar.hook: +# +# [Trigger] +# Operation = Upgrade +# Type = Package +# Target = * +# +# [Action] +# Description = Updating statusbar... +# When = PostTransaction +# Exec = /usr/bin/pkill -RTMIN+8 dwmblocks # Or i3blocks if using i3. + +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e sb-popupgrade ;; + 2) notify-send "$(/usr/bin/pacman -Qu)" ;; + 3) notify-send "🎁 Upgrade module" "πŸ“¦: number of upgradable packages +- Left click to upgrade packages +- Middle click to show upgradable packages" ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +pacman -Qu | grep -Fcv "[ignored]" | sed "s/^/ /;s/^ 0$//g" diff --git a/.local/bin/statusbar/sb-popupgrade b/.local/bin/statusbar/sb-popupgrade new file mode 100755 index 0000000..900f2a6 --- /dev/null +++ b/.local/bin/statusbar/sb-popupgrade @@ -0,0 +1,9 @@ +#!/bin/sh + +printf "Beginning upgrade.\\n" + +yay -Syu +pkill -RTMIN+8 "${STATUSBAR:-i3blocks}" + +printf "\\nUpgrade complete.\\nPress to exit window.\\n\\n" +read -r _ diff --git a/.local/bin/statusbar/sb-volume b/.local/bin/statusbar/sb-volume new file mode 100755 index 0000000..2676ead --- /dev/null +++ b/.local/bin/statusbar/sb-volume @@ -0,0 +1,39 @@ +#!/bin/sh + +# Prints the current volume or πŸ”‡ if muted. + +case $BLOCK_BUTTON in + 1) setsid -w -f "$TERMINAL" -e pulsemixer; pkill -RTMIN+10 "${STATUSBAR:-i3blocks}" ;; + 2) wpctl set-mute @DEFAULT_SINK@ toggle ;; + 4) wpctl set-volume @DEFAULT_SINK@ 1%+ ;; + 5) wpctl set-volume @DEFAULT_SINK@ 1%- ;; + 3) notify-send "πŸ“’ Volume module" "\- Shows volume πŸ”Š, πŸ”‡ if muted. +- Middle click to mute. +- Scroll to change." ;; + 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +vol="$(wpctl get-volume @DEFAULT_AUDIO_SINK@)" + +# If muted, print πŸ”‡ and exit. +[ "$vol" != "${vol%\[MUTED\]}" ] && echo  && exit + +vol="${vol#Volume: }" + +split() { + # For ommiting the . without calling and external program. + IFS=$2 + set -- $1 + printf '%s' "$@" +} + +vol="$(printf "%.0f" "$(split "$vol" ".")")" + +case 1 in + $((vol >= 70)) ) icon=" " ;; + $((vol >= 30)) ) icon=" " ;; + $((vol >= 1)) ) icon=" " ;; + * ) echo  && exit ;; +esac + +echo "$icon $vol%" -- cgit v1.2.3