diff --git a/statusbar/.local/bin/statusbar/bluetooth b/statusbar/.local/bin/statusbar/bluetooth new file mode 100755 index 0000000..eeb4cd2 --- /dev/null +++ b/statusbar/.local/bin/statusbar/bluetooth @@ -0,0 +1,7 @@ +#!/bin/sh + +if [ "$(systemctl is-active bluetooth.service)" = "active" ]; then + echo "" +else + echo "" +fi diff --git a/statusbar/.local/bin/statusbar/clock b/statusbar/.local/bin/statusbar/clock new file mode 100755 index 0000000..f63690d --- /dev/null +++ b/statusbar/.local/bin/statusbar/clock @@ -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//;s/..27m/<\/span><\/b>/")" && notify-send "Appointments" "$(khal list -d prayer_calender_local)" ;; +esac + +date "+$icon%H:%M" diff --git a/statusbar/.local/bin/statusbar/covid b/statusbar/.local/bin/statusbar/covid new file mode 100755 index 0000000..bef5530 --- /dev/null +++ b/statusbar/.local/bin/statusbar/covid @@ -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 }' diff --git a/statusbar/.local/bin/statusbar/cpu b/statusbar/.local/bin/statusbar/cpu new file mode 100755 index 0000000..e120b83 --- /dev/null +++ b/statusbar/.local/bin/statusbar/cpu @@ -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}' diff --git a/statusbar/.local/bin/statusbar/cpubars b/statusbar/.local/bin/statusbar/cpubars new file mode 100755 index 0000000..231207f --- /dev/null +++ b/statusbar/.local/bin/statusbar/cpubars @@ -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" diff --git a/statusbar/.local/bin/statusbar/disk b/statusbar/.local/bin/statusbar/disk new file mode 100755 index 0000000..13eb6a7 --- /dev/null +++ b/statusbar/.local/bin/statusbar/disk @@ -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}')" diff --git a/statusbar/.local/bin/statusbar/docker b/statusbar/.local/bin/statusbar/docker new file mode 100755 index 0000000..16875a6 --- /dev/null +++ b/statusbar/.local/bin/statusbar/docker @@ -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 diff --git a/statusbar/.local/bin/statusbar/github b/statusbar/.local/bin/statusbar/github new file mode 100755 index 0000000..9ab5ea7 --- /dev/null +++ b/statusbar/.local/bin/statusbar/github @@ -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 diff --git a/statusbar/.local/bin/statusbar/internet b/statusbar/.local/bin/statusbar/internet new file mode 100755 index 0000000..85081a4 --- /dev/null +++ b/statusbar/.local/bin/statusbar/internet @@ -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)" diff --git a/statusbar/.local/bin/statusbar/mail b/statusbar/.local/bin/statusbar/mail new file mode 100755 index 0000000..3d587fb --- /dev/null +++ b/statusbar/.local/bin/statusbar/mail @@ -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" diff --git a/statusbar/.local/bin/statusbar/memory b/statusbar/.local/bin/statusbar/memory new file mode 100755 index 0000000..5fcba15 --- /dev/null +++ b/statusbar/.local/bin/statusbar/memory @@ -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))}' diff --git a/statusbar/.local/bin/statusbar/microphone b/statusbar/.local/bin/statusbar/microphone new file mode 100755 index 0000000..ded5a01 --- /dev/null +++ b/statusbar/.local/bin/statusbar/microphone @@ -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 diff --git a/statusbar/.local/bin/statusbar/music b/statusbar/.local/bin/statusbar/music new file mode 100755 index 0000000..288485f --- /dev/null +++ b/statusbar/.local/bin/statusbar/music @@ -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 diff --git a/statusbar/.local/bin/statusbar/nettraf b/statusbar/.local/bin/statusbar/nettraf new file mode 100755 index 0000000..e83f325 --- /dev/null +++ b/statusbar/.local/bin/statusbar/nettraf @@ -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) diff --git a/statusbar/.local/bin/statusbar/news b/statusbar/.local/bin/statusbar/news new file mode 100755 index 0000000..f880e7b --- /dev/null +++ b/statusbar/.local/bin/statusbar/news @@ -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)" diff --git a/statusbar/.local/bin/statusbar/podcast b/statusbar/.local/bin/statusbar/podcast new file mode 100755 index 0000000..a458b9a --- /dev/null +++ b/statusbar/.local/bin/statusbar/podcast @@ -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)" diff --git a/statusbar/.local/bin/statusbar/reddit b/statusbar/.local/bin/statusbar/reddit new file mode 100755 index 0000000..576e30c --- /dev/null +++ b/statusbar/.local/bin/statusbar/reddit @@ -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 diff --git a/statusbar/.local/bin/statusbar/seperator b/statusbar/.local/bin/statusbar/seperator new file mode 100755 index 0000000..9c45e69 --- /dev/null +++ b/statusbar/.local/bin/statusbar/seperator @@ -0,0 +1,3 @@ +#!/bin/sh + +echo "║" diff --git a/statusbar/.local/bin/statusbar/toggl b/statusbar/.local/bin/statusbar/toggl new file mode 100755 index 0000000..01f73a6 --- /dev/null +++ b/statusbar/.local/bin/statusbar/toggl @@ -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 diff --git a/statusbar/.local/bin/statusbar/update-arch b/statusbar/.local/bin/statusbar/update-arch new file mode 100755 index 0000000..4c6567e --- /dev/null +++ b/statusbar/.local/bin/statusbar/update-arch @@ -0,0 +1,6 @@ +#!/usr/bin/env sh + +yay +sudo pacman -Rs $(pacman -Qtdq) +pacrmorphans +pkill -RTMIN+9 "${STATUSBAR:-dwmblocks}" diff --git a/statusbar/.local/bin/statusbar/updates b/statusbar/.local/bin/statusbar/updates new file mode 100755 index 0000000..e80f88d --- /dev/null +++ b/statusbar/.local/bin/statusbar/updates @@ -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 diff --git a/statusbar/.local/bin/statusbar/usb b/statusbar/.local/bin/statusbar/usb new file mode 100755 index 0000000..f3c984b --- /dev/null +++ b/statusbar/.local/bin/statusbar/usb @@ -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 diff --git a/statusbar/.local/bin/statusbar/volume b/statusbar/.local/bin/statusbar/volume new file mode 100755 index 0000000..9aa30a4 --- /dev/null +++ b/statusbar/.local/bin/statusbar/volume @@ -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%" diff --git a/statusbar/.local/bin/statusbar/vpn b/statusbar/.local/bin/statusbar/vpn new file mode 100755 index 0000000..4aade37 --- /dev/null +++ b/statusbar/.local/bin/statusbar/vpn @@ -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 diff --git a/statusbar/.local/bin/statusbar/weather b/statusbar/.local/bin/statusbar/weather new file mode 100755 index 0000000..2843329 --- /dev/null +++ b/statusbar/.local/bin/statusbar/weather @@ -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'