aboutsummaryrefslogtreecommitdiff
path: root/.local/bin
diff options
context:
space:
mode:
Diffstat (limited to '.local/bin')
-rwxr-xr-x.local/bin/statusbar/sb-clock29
-rwxr-xr-x.local/bin/statusbar/sb-doppler22
-rwxr-xr-x.local/bin/statusbar/sb-forecast57
-rwxr-xr-x.local/bin/statusbar/sb-internet43
-rwxr-xr-x.local/bin/statusbar/sb-mailbox20
-rwxr-xr-x.local/bin/statusbar/sb-memory13
-rwxr-xr-x.local/bin/statusbar/sb-microphone34
-rwxr-xr-x.local/bin/statusbar/sb-nettraf29
-rwxr-xr-x.local/bin/statusbar/sb-volume36
9 files changed, 283 insertions, 0 deletions
diff --git a/.local/bin/statusbar/sb-clock b/.local/bin/statusbar/sb-clock
new file mode 100755
index 0000000..b2ed96a
--- /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 $1 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) hyprctl dispatch exec "$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" ;;
+ 6) hyprctl dispatch exec "$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..e6062a3
--- /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() { hyprctl dispatch exec "[float; size 800 800;]" "imv \"$doppler\" -H 1200 -W 1200" ;}
+
+case $1 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." ;;
+ 6) hyprctl dispatch exec "$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..699c868
--- /dev/null
+++ b/.local/bin/statusbar/sb-forecast
@@ -0,0 +1,57 @@
+#!/bin/sh
+
+# Displays today's precipication chance (β˜”), and daily low (πŸ₯Ά) and high (🌞).
+# Usually intended for the statusbar.
+LOCATION="Moscow"
+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 "β˜”%s πŸ₯Ά%sΒ° 🌞%sΒ°\n" "$(getprecipchance)" $(getdailyhighlow)
+}
+
+openterm() {
+ hyprctl dispatch exec "[float; size 1800 1300;]" '$TERMINAL -e sh -c "curl wttr.in/Moscow; read _"'
+}
+
+case $1 in
+ 1) hyprctl dispatch exec "[float; size 1800 1100;]" "$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" ;;
+ 6) hyprctl dispatch exec "$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..7802f39
--- /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/wg0/operstate 2>/dev/null)" ];then
+ doas wg-quick up wg0
+ notify-send "πŸ”’ Internet module" "Connected to VPN"
+ else
+ doas wg-quick down wg0
+ notify-send "πŸ”’ Internet module" "Disconnected from VPN"
+ fi
+}
+
+case $1 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
+" ;;
+ 6) hyprctl dispatch exec "$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..b03724f
--- /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 $1 in
+ 1) hyprctl dispatch exec '$TERMINAL -e neomutt'; pkill -RTMIN+12 waybar ;;
+ 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" ;;
+ 6) hyprctl dispatch exec "$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..c39488f
--- /dev/null
+++ b/.local/bin/statusbar/sb-memory
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+case $1 in
+ 1) notify-send "🧠 Memory hogs" "$(ps axch -o cmd:15,%mem --sort=-%mem | head)" ;;
+ 2) hyprctl dispatch exec '$TERMINAL -e sh -c "btop"' ;;
+ 3) notify-send "🧠 Memory module" "\- Shows Memory Used/Total.
+- Click to show memory hogs.
+- Middle click to open btop." ;;
+ 6) hyprctl dispatch exec "$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..610eb21
--- /dev/null
+++ b/.local/bin/statusbar/sb-microphone
@@ -0,0 +1,34 @@
+#!/bin/sh
+
+# Prints the current microphone volume or ο„± if muted.
+
+case $1 in
+ 1) hyprctl dispatch exec "$TERMINAL -e pulsemixer" ;;
+ 3) notify-send "🎀 Microphone volume module" "\- Shows volume πŸŽ™οΈ, ο„± if muted.
+- Middle click to mute.
+- Scroll to change." ;;
+ 6) hyprctl dispatch exec "$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..0f4201b
--- /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 $1 in
+ 1) hyprctl dispatch exec "$TERMINAL -e bmon" ;;
+ 3) notify-send "🌐 Network traffic module" "πŸ”»: Traffic received
+πŸ”Ί: Traffic transmitted" ;;
+ 6) hyprctl dispatch exec "$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-volume b/.local/bin/statusbar/sb-volume
new file mode 100755
index 0000000..3b77433
--- /dev/null
+++ b/.local/bin/statusbar/sb-volume
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+# Prints the current volume or πŸ”‡ if muted.
+
+case $1 in
+ 1) hyprctl dispatch exec "$TERMINAL -e pulsemixer" ;;
+ 3) notify-send "πŸ“’ Volume module" "\- Shows volume πŸ”Š, πŸ”‡ if muted.
+- Middle click to mute.
+- Scroll to change." ;;
+ 6) hyprctl dispatch exec "$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%"