diff options
author | awy <awy@awy.one> | 2024-11-28 17:49:11 +0300 |
---|---|---|
committer | awy <awy@awy.one> | 2024-11-28 17:49:11 +0300 |
commit | abeb2dcdf2f2e6ca3ed1836d8cf3d6edf93129f3 (patch) | |
tree | b67df3bfdaeddf4165361899053cb4c74d2681e5 /.local/bin/statusbar |
upload
Diffstat (limited to '.local/bin/statusbar')
-rwxr-xr-x | .local/bin/statusbar/sb-clock | 29 | ||||
-rwxr-xr-x | .local/bin/statusbar/sb-doppler | 22 | ||||
-rwxr-xr-x | .local/bin/statusbar/sb-forecast | 53 | ||||
-rwxr-xr-x | .local/bin/statusbar/sb-internet | 43 | ||||
-rwxr-xr-x | .local/bin/statusbar/sb-mailbox | 20 | ||||
-rwxr-xr-x | .local/bin/statusbar/sb-memory | 12 | ||||
-rwxr-xr-x | .local/bin/statusbar/sb-microphone | 37 | ||||
-rwxr-xr-x | .local/bin/statusbar/sb-nettraf | 29 | ||||
-rwxr-xr-x | .local/bin/statusbar/sb-news | 17 | ||||
-rwxr-xr-x | .local/bin/statusbar/sb-pacpackages | 29 | ||||
-rwxr-xr-x | .local/bin/statusbar/sb-popupgrade | 9 | ||||
-rwxr-xr-x | .local/bin/statusbar/sb-volume | 39 |
12 files changed, 339 insertions, 0 deletions
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 ' ')\>/<b><span color='red'>&<\/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<signed number>" + 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 +<b>Note:</b> 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 <Enter> 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%" |