commit 31b35db7dae35ebc708c8ff59efd4d75c2b84c24 Author: Jasper Spahl Date: Sat Mar 26 15:33:05 2022 +0100 inital commit diff --git a/battery b/battery new file mode 100755 index 0000000..981fc3a --- /dev/null +++ b/battery @@ -0,0 +1,27 @@ +#!/bin/sh + +# Prints all batteries, their percentage remaining and an emoji corresponding +# to charge status (πŸ”Œ for plugged up, πŸ”‹ for discharging on battery, etc.). + +case $BLOCK_BUTTON in + 3) notify-send "πŸ”‹ Battery module" "πŸ”‹: discharging +πŸ›‘: not charging +β™»: stagnant charge +πŸ”Œ: charging +⚑: charged +❗: battery very low!" ;; +esac + +# Loop through all attached batteries. +for battery in /sys/class/power_supply/BAT? +do + # Get its remaining capacity and charge status. + capacity=$(cat "$battery"/capacity) || break + status=$(sed "s/Discharging/πŸ”‹/;s/Not charging/πŸ›‘/;s/Charging/πŸ”Œ/;s/Unknown/♻️/;s/Full/⚑/" "$battery"/status) + + # If it is discharging and 25% or less, we will add a ❗ as a warning. + [ "$capacity" -le 25 ] && [ "$status" = "πŸ”‹" ] && warn="❗" + + printf "%s%s%s%% " "$status" "$warn" "$capacity" + unset warn +done | sed s/\ $/\\n/ diff --git a/clock b/clock new file mode 100755 index 0000000..f5abd79 --- /dev/null +++ b/clock @@ -0,0 +1,11 @@ +#!/bin/sh + +#date '+%a %d. %B %Y %H:%M' +date '+%a %d.%m.%Y %H:%M' + +case $BLOCK_BUTTON in + 1) notify-send "This Month" "$(cal --color=always | sed "s/\x1B\[7m//;s/\x1B\[27m/<\/span><\/b>/")" && notify-send "Appointments" "$(calcurse -d3)" ;; + 2) $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" ;; +esac diff --git a/disk b/disk new file mode 100755 index 0000000..269eba7 --- /dev/null +++ b/disk @@ -0,0 +1,22 @@ +#!/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)" ;; + 3) notify-send "πŸ’½ Disk module" "\- Shows used hard drive space. +- Click to show all disk info." ;; +esac + +case "$location" in + "/home"* ) icon="🏠" ;; + "/mnt"* ) icon="πŸ’Ύ" ;; + *) icon="πŸ–₯ ";; +esac + +printf "%s: %s\n" "$icon" "$(df -h "$location" | awk ' /[0-9]/ {print $3 "/" $2}')" diff --git a/internet b/internet new file mode 100755 index 0000000..518d6d7 --- /dev/null +++ b/internet @@ -0,0 +1,19 @@ +#!/bin/sh + +# Show wifi πŸ“Ά and percent strength or πŸ“‘ if none. +# Show 🌐 if connected to ethernet or ❎ if none. + +case $BLOCK_BUTTON in + 1) setsid "$TERMINAL" -e nmtui & ;; + 3) notify-send "🌐 Internet module" "\- Click to connect +πŸ“‘: no wifi connection +πŸ“Ά: wifi connection with quality +❎: no ethernet +🌐: ethernet working +" ;; +esac + +grep -q "down" /sys/class/net/w*/operstate && wifiicon="πŸ“‘" || + wifiicon="$(grep "^\s*w" /proc/net/wireless | awk '{ print "πŸ“Ά", int($3 * 100 / 70) "%" }')" + +printf "%s %s\n" "$wifiicon" "$(sed "s/down/❎/;s/up/🌐/" /sys/class/net/e*/operstate)" diff --git a/mailbox b/mailbox new file mode 100755 index 0000000..0d15e29 --- /dev/null +++ b/mailbox @@ -0,0 +1,49 @@ +#!/bin/sh + +# i3blocks mail module. +# Displays number of unread mail and an loading icon if updating. +# When clicked, brings up `neomutt`. +messageinfo() { notify-send --urgency=$urgency --app-name="πŸ“§ Mailbox" "πŸ“§ Mailbox:" "Acc: $to +From: $from +Subject: $subject +Reseved in $mailfolder" ;} +notify(){ + new=$(find $HOME/.local/share/mail/*/*/new/ -type f 2> /dev/null) + newcount=$(echo "$new" | sed '/^\s*$/d' | wc -l) + if [ "$newcount" -gt "0" ]; then + find $HOME/.local/share/mail/*/*/new/ -type f 2> /dev/null | while read file; do + # Extract subject and sender from mail. + to=$(echo "$file" | sed -E "s/\/home\/jasper\/.local\/share\/mail\/(.+)\/.*\/.*\/.*$/\1/") + mailfolder=$(echo $file | sed -E "s/\/home\/jasper\/.local\/share\/mail\/.*\/(.+)\/.*\/.*$/\1/") + from=$(awk '/^From: / && ++n ==1,/^\<.*\>:/' "$file" | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | awk '{ $1=""; if (NF>=3)$NF=""; print $0 }' | sed 's/^[[:blank:]]*[\"'\''\<]*//;s/[\"'\''\>]*[[:blank:]]*$//') + subject=$(awk '/^Subject: / && ++n == 1,/^\<.*\>: / && ++i == 2' "$file" | head -n 1 | perl -CS -MEncode -ne 'print decode("MIME-Header", $_)' | sed 's/^Subject: //' | sed 's/^{[[:blank:]]*[\"'\''\<]*//;s/[\"'\''\>]*[[:blank:]]*$//' | tr -d '\n') + case $mailfolder in + Spam ) urgency="low" ;; + Fritz-Box ) urgency="low" ;; + Schule ) urgency="critical" ;; + * ) urgency="normal" ;; + esac + case $to in + jspahl11@gmail.com ) urgency="low" ;; + * ) urgency=$urgency + esac + messageinfo & + done + fi +} + +case $BLOCK_BUTTON in + 1) setsid -f "$TERMINAL" -e neomutt & ;; + 2) setsid -f mailsync >/dev/null & ;; + 3) notify-send -t 1000 "πŸ“¬ Mailbox module:" "\- Shows unread mail +- Shows πŸ”ƒ if syncing mail +- Left click opens neomutt +- Middle click syncs mail" && notify >/dev/null ;; + 6) "$TERMINAL" -e "$EDITOR" "$0"&;; +esac + +unread="$(find ${XDG_DATA_HOME:-$HOME/.local/share}/mail/*/*/new/* -type f | wc -l 2>/dev/null)" + +icon="$(cat "/tmp/imapsyncicon_$USER")" 2>/dev/null + +[ "$unread" = "0" ] && [ "$icon" = "" ] || echo "πŸ“¬ $unread$(cat "/tmp/imapsyncicon_$USER" 2>/dev/null)" diff --git a/mscplyr b/mscplyr new file mode 100755 index 0000000..0eed218 --- /dev/null +++ b/mscplyr @@ -0,0 +1,55 @@ +#!/bin/sh + +filter() { + sed "/^volume:/d" | tac | sed -e "s/\\&/&/g;s/\\[paused\\].*//g;s/\\[playing\\].*//g" | tr -d '\n' |sed -e "s/$/<\/span>\n/g" +} +player="" + +[ -z $BLOCK_INSTANCE ] || player="--player=$BLOCK_INSTANCE" + +case $BLOCK_INSTANCE in + "mpd") playprog="$TERMINAL -e ncmpcpp" ;; + "spotify") playprog="$TERMINAL -e spt" ;; + "cmus") playprog="$TERMINAL -e cmus" ;; + "vlc" ) playprog="vlc" ;; + *) playprog="" ;; +esac + +if [ "$BLOCK_INSTANCE" == "mpd" ]; then + status() { mpc status | filter ;} + toggle() { mpc toggle | filter ;} + next() { mpc next | filter ;} + prev() { mpc prev | filter ;} +else + status() { + playerctl metadata $player -f '{{artist}} - {{title}} +[{{lc(status)}}]' | filter + } + + toggle() { + playerctl play-pause $player + status + } + + next() { + playerctl next $player + status + } + prev() { + playerctl previous $player + status + } +fi + +case $BLOCK_BUTTON in + 1) status && setsid $playprog & ;; + 2) toggle ;; + 3) status && notify-send "🎡 Music module" "\- Shows playing song. +- Italic when paused. +- Left click opens player. +- Middle click pauses. +- Scroll changes tracks.:" ;; + 4) prev ;; + 5) next ;; + *) status ;; +esac; exit diff --git a/mscplyr-dwm b/mscplyr-dwm new file mode 100755 index 0000000..0ee15a7 --- /dev/null +++ b/mscplyr-dwm @@ -0,0 +1,79 @@ +#!/bin/sh + +filter() { + sed "/^volume:/d" | tac | sed -e "s/\\&/&/g;s/\\[paused\\].*/ /g;s/\\[playing\\].*/ /g" | tr -d '\n' |sed -e "s/$/\n/g" +} +player="" + +[ -z $BLOCK_INSTANCE ] || player="--player=$BLOCK_INSTANCE" + +case $BLOCK_INSTANCE in + "mpd") playprog="$TERMINAL -e ncmpcpp" ;; + "spotify"|"spotifyd") playprog="$TERMINAL -e spt" ;; + "cmus") playprog="$TERMINAL -e cmus" ;; + "vlc" ) playprog="vlc" ;; + *) playprog="" ;; +esac + +case $BLOCK_INSTANCE in + "mpd") + playprog="$TERMINAL -e ncmpcpp" + status() { mpc status | filter ;} + toggle() { mpc toggle | filter ;} + next() { mpc next | filter ;} + prev() { mpc prev | filter ;};; + "spotify"|"spotifyd") + playprog="$TERMINAL -e spt" + status() { + spt pb -s + } + + toggle() { + spt pb -t + status + } + + next() { + spt pb -n + status + } + prev() { + spt pb -p + status + } + ;; + *) + status() { + playerctl metadata $player -f '{{artist}} - {{title}} +[{{lc(status)}}]' | filter + } + + toggle() { + playerctl play-pause $player + status + } + + next() { + playerctl next $player + status + } + prev() { + playerctl previous $player + status + } + ;; +esac + +case $BLOCK_BUTTON in + 1) status && setsid $playprog & ;; + 2) toggle ;; + 3) status && notify-send "🎡 Music module" "\- Shows playing song. +- Italic when paused. +- Left click opens player. +- Middle click pauses. +- Scroll changes tracks.:" ;; + 4) prev ;; + 5) next ;; + 6) status && setsid $TERMINAL -e $EDITOR $0 &;; + *) status ;; +esac; exit diff --git a/music b/music new file mode 100755 index 0000000..1412ae3 --- /dev/null +++ b/music @@ -0,0 +1,18 @@ +#!/bin/sh + +filter() { + sed "/^volume:/d" | tac | sed -e "s/\\&/&/g;s/\\[paused\\].*//g;s/\\[playing\\].*//g" | tr -d '\n' | sed -e "s/$/<\\/span>\n/g" + } + +case $BLOCK_BUTTON in + 1) mpc status | filter && setsid "$TERMINAL" -e ncmpcpp & ;; # right click, pause/unpause + 2) mpc toggle | filter ;; # right click, pause/unpause + 3) mpc status | filter && notify-send "🎡 Music module" "\- Shows mpd song playing. +- Italic when paused. +- Left click opens ncmpcpp. +- Middle click pauses. +- Scroll changes track.";; # right click, pause/unpause + 4) mpc prev | filter ;; # scroll up, previous + 5) mpc next | filter ;; # scroll down, next + *) mpc status | filter ;; +esac; exit diff --git a/news b/news new file mode 100755 index 0000000..39f5db2 --- /dev/null +++ b/news @@ -0,0 +1,17 @@ +#!/bin/sh + +# Displays number of unread news items and an loading icon if updating. +# When clicked, bring 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." ;; + 6) "$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/pacpackages b/pacpackages new file mode 100755 index 0000000..7aef7be --- /dev/null +++ b/pacpackages @@ -0,0 +1,29 @@ +#!/bin/sh + +# Display number of upgradebles packages. +# For this to work, have a `pacman -Sy` command run in the background as a +# cronjob every so often as root. This sctipt 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 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" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +pacman -Qu | grep -Fcv "[ignored]" | sed "s/^/πŸ“¦/;s/^πŸ“¦0$//g" diff --git a/temps b/temps new file mode 100755 index 0000000..c652f90 --- /dev/null +++ b/temps @@ -0,0 +1,31 @@ +#!/bin/sh + +case $BLOCK_BUTTON in + 1) setsid "$TERMINAL" -e gotop ;; + 3) notify-send "πŸ“° Temperature module" "\- Shows Cpu temps items +- Left click opens gotop" ;; + 6) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +info=$(sensors) +temps=$(echo "$info" | grep "Β°C" | sed -r 's/^.*\+([0-9]+)\.[0-9]Β°C.*\(.*\).*$/\1/g') +fan=$(echo "$info" | grep "RPM" | sed -r 's/^.* ([0-9]+ RPM)/\1/g') + +rec="0" +temps="$(for temp in $temps; do + [ "$temp" -gt "$rec" ] && rec="$temp" + echo $rec +done | tac | sed 1q)" +if [ "$temps" -gt "80" ]; then + temps=$(echo "$tempsΒ°C") + icon="" +elif [ "$temps" -gt "50" ];then + temps=$(echo "$tempsΒ°C") + icon="" +else + temps=$(echo "$tempsΒ°C") + icon="ο‹‹" +fi + +#echo "$temps" +printf "%s %s  %s\\n" "$icon" "$temps" "$fan" diff --git a/temps-dwm b/temps-dwm new file mode 100755 index 0000000..2437ca8 --- /dev/null +++ b/temps-dwm @@ -0,0 +1,28 @@ +#!/bin/sh + +case $BLOCK_BUTTON in + 1) setsid "$TERMINAL" -e gotop &;; + 3) notify-send "πŸ“° Temperature module" "\- Shows Cpu temps items +- Left click opens gotop" ;; + 6) setsid "$TERMINAL" -e "$EDITOR" "$0" &;; +esac + +info=$(sensors) +temps=$(echo "$info" | grep "Β°C" | sed -r 's/^.*\+([0-9]+)\.[0-9]Β°C.*\(.*\).*$/\1/g') +fan=$(echo "$info" | grep "RPM" | sed -r 's/^.* ([0-9]+ RPM)/\1/g') + +rec="0" +temps="$(for temp in $temps; do + [ "$temp" -gt "$rec" ] && rec="$temp" + echo $rec +done | tac | sed 1q)" +if [ "$temps" -gt "80" ]; then + icon="" +elif [ "$temps" -gt "50" ];then + icon="" +else + icon="ο‹‹" +fi + +#echo "$temps" +printf "%s %s  %s\\n" "$icon" "$temps" "$fan" diff --git a/voc b/voc new file mode 100755 index 0000000..2261cd1 --- /dev/null +++ b/voc @@ -0,0 +1,13 @@ +#!/bin/sh +english=$(sed -E 's/.*\|.*\|([0-9]{2})\.([0-9]{2})\.([0-9]{4})\|[0-9\|]+/\3\2\1/g' ~/.vokabeln/English.csv | while read line; do [[ $line -le $(date +%Y%m%d) ]] && echo $line; done | wc -l | sed -E 's/^([1-9][0-9]*)$/πŸ‡ΊπŸ‡Έ:\1/g;s/^0$//g') + +franz=$(sed -E 's/.*\|.*\|([0-9]{2})\.([0-9]{2})\.([0-9]{4})\|[0-9\|]+/\3\2\1/g' ~/.vokabeln/FranzΓΆsisch.csv | while read line; do [[ $line -le $(date +%Y%m%d) ]] && echo $line; done | wc -l | sed -E 's/^([1-9][0-9]*)$/πŸ‡«πŸ‡·:\1/g;s/^0$//g') + +echo $english $franz + +case $BLOCK_BUTTON in + 1) ($TERMINAL -e vokabeln.py && (pkill -RTMIN+20 "${STATUSBAR:-blocks}" >/dev/null 2>&1 ) 2>/dev/null ) & ;; + 3) notify-send "Vocablurary module" "\- Left click to open vokabeln.py in a terminal" ;; +esac + + diff --git a/volume b/volume new file mode 100755 index 0000000..5782070 --- /dev/null +++ b/volume @@ -0,0 +1,40 @@ +#!/bin/sh + +# Prints the current volume or πŸ”‡ if muted. Uses PulseAudio by default, +# uncomment the ALSA lines if you remove PulseAudio. + +case $BLOCK_BUTTON in + #1) setsid "$TERMINAL" -e alsamixer & ;; + #2) amixer sset Master toggle ;; + #4) amixer sset Master 5%+ >/dev/null 2>/dev/null ;; + #5) amixer sset Master 5%- >/dev/null 2>/dev/null ;; + 1) setsid "$TERMINAL" -e pulsemixer & ;; + 2) pamixer -t ;; + 4) pamixer --allow-boost -i 1 ;; + 5) pamixer --allow-boost -d 1 ;; + 6) setsid "$TERMINAL" -e $EDITOR "$0" & ;; + 3) notify-send "πŸ“’ Volume module" "\- Shows volume πŸ”Š, πŸ”‡ if muted. +- Middle click to mute. +- Scroll to change." +esac + +volstat="$(pactl list sinks)" +#volstat="$(amixer get Master)" # ALSA only equivalent. + +#volstat="$(echo "$volstat" | tail -n +$(echo "$volstat" | grep -n "#$(pactl list short sinks | grep "RUNNING" | awk '{print $1}')" | sed 's/:.*$//g'))" + +echo "$volstat" | grep -q "Stumm: ja" && printf "πŸ”‡\\n" && exit +#echo "$volstat" | grep "\[off\]" >/dev/null && printf "πŸ”‡\\n" && exit # ALSA + +vol="$(echo "$volstat" | grep '[0-9]\+%' | sed "s,.* \([0-9]\+\)%.*,\1,;1q")" +#vol=$(echo "$volstat" | grep -o "\[[0-9]\+%\]" | sed "s/[^0-9]*//g;1q") # ALSA + +if [ "$vol" -gt "70" ]; then + icon="πŸ”Š" +elif [ "$vol" -lt "30" ]; then + icon="πŸ”ˆ" +else + icon="πŸ”‰" +fi + +printf "%s %s%%\\n" "$icon" "$vol" diff --git a/weather b/weather new file mode 100755 index 0000000..db760eb --- /dev/null +++ b/weather @@ -0,0 +1,36 @@ +#!/bin/sh + +# Displays todays precipication chance (β˜”) and daily low (❄) and high (🌞). +# Usually intended for the statusbar. + +# If we have internet, get a weather report from wttr.in and store it locally. +# You could set up a shell alias to view the full file in a pager in the +# terminal if desired. This function will only be run once a day when needed. +getforecast() { ping -q -c 1 example.org >/dev/null && +curl -sf "wttr.in/Stutensee" > "${XDG_DATA_HOME:-$HOME/.local/share}/weatherreport" || exit 1 ;} + +# Some very particular and terse stream manipulation. We get the maximum +# precipication chance and the daily high and low from the downloaded file and +# display them with coresponding emojis. +showweather() { printf "%s" "$(sed '16q;d' "${XDG_DATA_HOME:-$HOME/.local/share}/weatherreport" | + grep -wo "[0-9]*%" | sort -rn | sed "s/^/β˜” /g;1q" | tr -d '\n')" +sed '13q;d' "${XDG_DATA_HOME:-$HOME/.local/share}/weatherreport" | grep -o "m\\([-+]\\)*[0-9]\\+" | sort -n -t 'm' -k 2n | sed -e 1b -e '$!d' | tr '\n|m' ' ' | awk '{print " ❄️",$1 "Β°","🌞",$2 "Β°"}' ;} + +# The BLOCK_BUTTON bloat for clicking in i3. +case $BLOCK_BUTTON in + 1) setsid "$TERMINAL" -e less -Srf "${XDG_DATA_HOME:-$HOME/.local/share}/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) "$TERMINAL" -e "$EDITOR" "$0" ;; +esac + +# The test if our forcecast is updated to the day. If it isn't download a new +# weather report from wttr.in with the above function. +[ "$(stat -c %y "${XDG_DATA_HOME:-$HOME/.local/share}/weatherreport" 2>/dev/null | cut -d' ' -f1)" = "$(date '+%Y-%m-%d')" ] || + getforecast + +showweather