1
0
mirror of https://github.com/alrayyes/dotfiles/ synced 2023-11-14 15:56:30 +00:00

feat(dwm): initial statusbar scripts

This commit is contained in:
Ryan Kes 2021-03-13 15:35:22 +01:00
parent 36703e763e
commit d97daf4ad2
25 changed files with 492 additions and 0 deletions

View File

@ -0,0 +1,7 @@
#!/bin/sh
if [ "$(systemctl is-active bluetooth.service)" = "active" ]; then
echo ""
else
echo ""
fi

View File

@ -0,0 +1,25 @@
#!/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 --color=always | sed "s/..7m/<b><span color=\"red\">/;s/..27m/<\/span><\/b>/")" && notify-send "Appointments" "$(khal list -d prayer_calender_local)" ;;
esac
date "+$icon%H:%M"

View File

@ -0,0 +1,7 @@
#!/usr/bin/env sh
case $BLOCK_BUTTON in
1) notify-send Covid "$(curl -4 https://corona-stats.online/Netherlands?emojis=true | sed 's/\x1b\[[0-9;]*m//g')" ;;
esac
curl --silent "https://corona-stats.online/Netherlands" | sed -n '4p' | sed 's/\x1b\[[0-9;]*m//g' | sed 's/[\ \t]//g' | awk -F '│' '{ print "😷" $3, "💀" $5, "🛌" $4, "🏥" $9 }'

View File

@ -0,0 +1,8 @@
#!/bin/sh
case $BLOCK_BUTTON in
1) notify-send "🖥 CPU hogs" "$(ps axch -o cmd:15,%cpu --sort=-%cpu | head)\\n(100% per core)" ;;
3) setsid -f "$TERMINAL" -e htop ;;
esac
sensors | awk '/Core 0/ {print "🌡" $3}'

View File

@ -0,0 +1,37 @@
#!/bin/sh
# Cache in tmpfs to improve speed and reduce SSD load
cache=/tmp/cpubarscache
case $BLOCK_BUTTON in
1) setsid -f "$TERMINAL" -e htop ;;
esac
# id total idle
stats=$(awk '/cpu[0-9]+/ {printf "%d %d %d\n", substr($1,4), ($2 + $3 + $4 + $5), $5 }' /proc/stat)
[ ! -f $cache ] && echo "$stats" >"$cache"
old=$(cat "$cache")
printf "🪨"
echo "$stats" | while read -r row; do
id=${row%% *}
rest=${row#* }
total=${rest%% *}
idle=${rest##* }
case "$(echo "$old" | awk '{if ($1 == id)
printf "%d\n", (1 - (idle - $3) / (total - $2))*100 /12.5}' \
id="$id" total="$total" idle="$idle")" in
"0") printf "▁" ;;
"1") printf "▂" ;;
"2") printf "▃" ;;
"3") printf "▄" ;;
"4") printf "▅" ;;
"5") printf "▆" ;;
"6") printf "▇" ;;
"7") printf "█" ;;
"8") printf "█" ;;
esac
done
printf "\\n"
echo "$stats" >"$cache"

View File

@ -0,0 +1,15 @@
#!/bin/sh
# Status bar module for disk space
# $1 should be drive mountpoint, otherwise assumed /.
location=${1:-/}
[ -d "$location" ] || exit
case $BLOCK_BUTTON in
1) notify-send "💽 Disk space" "$(df -h --output=target,used,size)" ;;
esac
printf "%s%s" "🏠" "$(df -h "/home" | awk ' /[0-9]/ {print $3 "/" $2}') "
printf "%s%s" "🖥" "$(df -h "/" | awk ' /[0-9]/ {print $3 "/" $2}')"

View File

@ -0,0 +1,13 @@
#!/usr/bin/env sh
case $BLOCK_BUTTON in
1) notify-send "Docker" "$(docker ps)" ;;
esac
count=$(docker ps -q | wc -l)
if [ ! "$count" -eq 0 ]; then
echo "🐳$count"
else
echo ""
fi

View File

@ -0,0 +1,15 @@
#!/bin/sh
token=$(getpassword githubnotifications)
case $BLOCK_BUTTON in
1) "$BROWSER" --new-tab https://github.com/notifications ;;
esac
count=$(curl -s -u alrayyes:"$token" https://api.github.com/notifications | jq 'length')
if [ ! "$count" -eq 0 ]; then
echo "🦊$count"
else
echo ""
fi

View File

@ -0,0 +1,19 @@
#!/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
case $BLOCK_BUTTON in
1)
"$TERMINAL" -e nmtui
pkill -RTMIN+17 dwmblocks
;;
esac
case "$(cat /sys/class/net/w*/operstate 2>/dev/null)" in
down) wifiicon="📡 " ;;
up) wifiicon="$(awk '/^\s*w/ { print "📶", int($3 * 100 / 70) "% " }' /proc/net/wireless)" ;;
esac
printf "%s%s%s\n" "$wifiicon" "$(sed "s/down/❎/;s/up/🌐/" /sys/class/net/e*/operstate 2>/dev/null)"

View File

@ -0,0 +1,16 @@
#!/usr/bin/env sh
case $BLOCK_BUTTON in
1) setsid -f "$TERMINAL" -e neomutt ;;
3) setsid -f mailsync >/dev/null ;;
esac
unread="$(find ~/.local/share/mail/*/INBOX/new/* -type f 2>/dev/null | wc -l)"
if [ "$unread" -eq "0" ]; then
unread=""
fi
pidof mbsync >/dev/null 2>&1 && icon="🔃"
[ "$unread" = "" ] && [ "$icon" = "" ] || echo "📬$unread$icon"

View File

@ -0,0 +1,8 @@
#!/bin/sh
case $BLOCK_BUTTON in
1) notify-send "🧠 Memory hogs" "$(ps axch -o cmd:15,%mem --sort=-%mem | head)" ;;
3) setsid -f "$TERMINAL" -e htop ;;
esac
free --mebi | sed -n '2{p;q}' | awk '{printf ("🧠%2.2fGiB/%2.2fGiB\n", ( $3 / 1024), ($2 / 1024))}'

View File

@ -0,0 +1,24 @@
#!/bin/sh
# Prints the current volume or nothing if muted.
case $BLOCK_BUTTON in
1) setsid -f "$TERMINAL" -e pulsemixer ;;
2) pamixer -t ;;
9) pamixer --allow-boost -i 1 ;;
8) pamixer --allow-boost -d 1 ;;
esac
source=$(pamixer --list-sources | grep Yeti | awk '{print $1}')
if [ -n "$source" ]; then
vol="$(pamixer --source "$source" --get-volume)"
if [ "$vol" -gt "0" ]; then
icon="🎤"
fi
echo "$icon"
else
echo ""
fi

View File

@ -0,0 +1,21 @@
#!/bin/sh
player_status=$(playerctl status 2>/dev/null)
if [ "$player_status" = "Playing" ]; then
echo "⏯$(playerctl metadata artist) - $(playerctl metadata title)"
elif [ "$player_status" = "Paused" ]; then
echo "⏸ $(playerctl metadata artist) - $(playerctl metadata title)"
fi
case $BLOCK_BUTTON in
1)
playerctl previous
;;
2)
playerctl play-pause
;;
3)
playerctl next
;;
esac

View File

@ -0,0 +1,26 @@
#!/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 ;;
esac
update() {
sum=0
for arg; do
read -r i <"$arg"
sum=$((sum + i))
done
cache=${XDG_CACHE_HOME:-$HOME/.cache}/${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) $(numfmt --to=iec $tx)

View File

@ -0,0 +1,17 @@
#!/usr/bin/env sh
password=$(getpassword rss)
session_id=$(curl -s -d '{"op":"login","user":"alrayyes","password":"'"$password"'"}' "https://rss.higherlearning.eu/api/" | jq -r ".content.session_id")
count=$(curl -s -d '{"sid":"'$session_id'","op":"getUnread","feed_id":"0","is_cat":"1"}' "https://rss.higherlearning.eu/api/" | jq -r ".content.unread")
case $BLOCK_BUTTON in
1) setsid "$TERMINAL" -e newsboat ;;
2) setsid -f newsup exit >/dev/null ;;
esac
output=""
if [ "$count" -gt 0 ]; then
output="📰$count"
fi
cat /tmp/newsupdate 2>/dev/null || echo "$output""$(cat "${XDG_CONFIG_HOME:-$HOME/.config}"/newsboat/.update 2>/dev/null)"

View File

@ -0,0 +1,17 @@
#!/usr/bin/env sh
password=$(getpassword rss)
session_id=$(curl -s -d '{"op":"login","user":"alrayyes","password":"'"$password"'"}' "https://rss.higherlearning.eu/api/" | jq -r ".content.session_id")
count=$(curl -s -d '{"sid":"'$session_id'","op":"getUnread","feed_id":"10","is_cat":"1"}' "https://rss.higherlearning.eu/api/" | jq -r ".content.unread")
case $BLOCK_BUTTON in
1) setsid "$TERMINAL" -e podboat ;;
2) setsid -f newsup exit >/dev/null ;;
esac
output=""
if [ "$count" -gt 0 ]; then
output="📻$count"
fi
echo "$output""$(cat "${XDG_CONFIG_HOME:-$HOME/.config}"/newsboat/.update 2>/dev/null)"

View File

@ -0,0 +1,16 @@
#!/bin/sh
case $BLOCK_BUTTON in
1) "$BROWSER" --new-tab https://www.reddit.com ;;
esac
URL="https://www.reddit.com/message/unread/.json?feed=bc32fdcb4a67282ee7cac839c0a52083aadc79f0&user=alrayyes"
USERAGENT="polybar-scripts/notification-reddit:v1.0 u/reddituser"
notifications=$(curl -sf --user-agent "$USERAGENT" "$URL" | jq '.["data"]["children"] | length')
if [ -n "$notifications" ] && [ "$notifications" -gt 0 ]; then
echo "👾$notifications"
else
echo ""
fi

View File

@ -0,0 +1,3 @@
#!/bin/sh
echo "║"

View File

@ -0,0 +1,14 @@
#!/bin/sh
case $BLOCK_BUTTON in
1) "$BROWSER" --new-tab https://track.toggl.com/timer ;;
esac
token=$(getpassword toggl)
current="$(curl --silent -u "$token":api_token "https://api.track.toggl.com/api/v8/time_entries/current" | jq '.data.description' | sed 's/"//g')"
if [ "$current" != "null" ]; then
echo "⏲ $current"
else
echo ""
fi

View File

@ -0,0 +1,6 @@
#!/usr/bin/env sh
yay
sudo pacman -Rs $(pacman -Qtdq)
pacrmorphans
pkill -RTMIN+9 "${STATUSBAR:-dwmblocks}"

View File

@ -0,0 +1,25 @@
#!/bin/sh
case $BLOCK_BUTTON in
1) "$TERMINAL" -e ~/.local/bin/statusbar/update-arch ;;
esac
if ! updates_arch=$(checkupdates 2>/dev/null | wc -l); then
updates_arch=0
fi
if ! updates_aur=$(yay -Qum 2>/dev/null | wc -l); then
# if ! updates_aur=$(cower -u 2> /dev/null | wc -l); then
# if ! updates_aur=$(trizen -Su --aur --quiet | wc -l); then
# if ! updates_aur=$(pikaur -Qua 2> /dev/null | wc -l); then
# if ! updates_aur=$(rua upgrade --printonly 2> /dev/null | wc -l); then
updates_aur=0
fi
updates=$(("$updates_arch" + "$updates_aur"))
if [ "$updates" -gt 0 ]; then
echo "📦$updates"
else
echo ""
fi

View File

@ -0,0 +1,90 @@
#!/bin/sh
usb_print() {
devices=$(lsblk -Jplno NAME,TYPE,RM,SIZE,MOUNTPOINT,VENDOR)
output=""
counter=0
for unmounted in $(echo "$devices" | jq -r '.blockdevices[] | select(.type == "part") | select(.rm == true) | select(.mountpoint == null) | .name'); do
unmounted=$(echo "$unmounted" | tr -d "[:digit:]")
unmounted=$(echo "$devices" | jq -r '.blockdevices[] | select(.name == "'"$unmounted"'") | .vendor')
unmounted=$(echo "$unmounted" | tr -d ' ')
if [ $counter -eq 0 ]; then
space=""
else
space=" "
fi
counter=$((counter + 1))
output="$output$space $unmounted"
done
for mounted in $(echo "$devices" | jq -r '.blockdevices[] | select(.type == "part") | select(.rm == true) | select(.mountpoint != null) | .size'); do
if [ $counter -eq 0 ]; then
space=""
else
space=" "
fi
counter=$((counter + 1))
output="$output$space $mounted"
done
if [ "$output" ]; then
notify-send.py "USB" "$output" \
-i drive-removable-media-usb \
--replaces-process "usb-mount" &
fi
echo "$output"
}
usb_update() {
pid=$(cat "$path_pid")
if [ "$pid" != "" ]; then
kill -10 "$pid"
fi
}
path_pid="/tmp/polybar-system-usb-udev.pid"
case "$1" in
--update)
usb_update
;;
--mount)
devices=$(lsblk -Jplno NAME,TYPE,RM,MOUNTPOINT)
for mount in $(echo "$devices" | jq -r '.blockdevices[] | select(.type == "part") | select(.rm == true) | select(.mountpoint == null) | .name'); do
mountpoint=$(udisksctl mount --no-user-interaction -b "$mount")
mountpoint=$(echo "$mountpoint" | cut -d " " -f 4 | tr -d ".")
alacritty --class lf,lf -e lf "$mountpoint" &
done
usb_update
;;
--unmount)
devices=$(lsblk -Jplno NAME,TYPE,RM,MOUNTPOINT)
for unmount in $(echo "$devices" | jq -r '.blockdevices[] | select(.type == "part") | select(.rm == true) | select(.mountpoint != null) | .name'); do
udisksctl unmount --no-user-interaction -b "$unmount"
udisksctl power-off --no-user-interaction -b "$unmount"
done
usb_update
;;
*)
echo $$ >$path_pid
trap exit INT
trap "echo" USR1
while true; do
usb_print
sleep 60 &
wait
done
;;
esac

View File

@ -0,0 +1,24 @@
#!/bin/sh
# Prints the current volume or 🔇 if muted.
case $BLOCK_BUTTON in
1) setsid -f "$TERMINAL" -e pulsemixer ;;
2) pamixer -t ;;
9) pamixer --allow-boost -i 1 ;;
8) pamixer --allow-boost -d 1 ;;
esac
[ $(pamixer --get-mute) = true ] && echo 🔇 && exit
vol="$(pamixer --get-volume)"
if [ "$vol" -gt "70" ]; then
icon="🔊"
elif [ "$vol" -lt "30" ]; then
icon="🔈"
else
icon="🔉"
fi
echo "$icon$vol%"

View File

@ -0,0 +1,32 @@
#!/bin/sh
check_vpn() {
status="$(nmcli device status | grep -c "$1")"
if [ "$status" -gt "0" ]; then
icon=💂
if [ "$1" = "tun0" ]; then
icon=🔒
fi
echo "$icon$1"
fi
}
if [ -n "$1" ]; then
case $BLOCK_BUTTON in
1) case $1 in
"wg-0")
wg-quick down "$1"
notify-send -a wireguard --replaces-process wireguard-status-"$1" -i network-vpn-offline-symbolic "Wireguard $1" "Connection down" &
;;
"wg-1")
wg-quick down "$1"
notify-send -a wireguard --replaces-process wireguard-status-"$1" -i network-vpn-offline-symbolic "Wireguard $1" "Connection down" &
;;
esac ;;
esac
check_vpn "$1"
fi

View File

@ -0,0 +1,7 @@
#!/bin/sh
case $BLOCK_BUTTON in
1) notify-send "Weather" "$(curl -4 https://wttr.in/Amsterdam?T)" ;;
esac
curl --silent "https://wttr.in/Amsterdam?format=2" | sed 's///g'