inital commit

develop
Jasper Levin Spahl 3 years ago
commit 31b35db7da
Signed by: jasper
GPG Key ID: 91991C9808A18BB0

@ -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/

11
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/<b><span color=\"red\">/;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

22
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}')"

@ -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)"

@ -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: <span foreground=\"#b8bb26\"><b>$from</b></span>
Subject: $subject
<span foreground=\"#a89984\">Reseved in $mailfolder</span>" ;}
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)"

@ -0,0 +1,55 @@
#!/bin/sh
filter() {
sed "/^volume:/d" | tac | sed -e "s/\\&/&amp;/g;s/\\[paused\\].*/<span color=\"gray\" font_style=\"italic\">/g;s/\\[playing\\].*/<span>/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

@ -0,0 +1,79 @@
#!/bin/sh
filter() {
sed "/^volume:/d" | tac | sed -e "s/\\&/&amp;/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

18
music

@ -0,0 +1,18 @@
#!/bin/sh
filter() {
sed "/^volume:/d" | tac | sed -e "s/\\&/&amp;/g;s/\\[paused\\].*/<span color=\"gray\" font_style=\"italic\">/g;s/\\[playing\\].*/<span>/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

17
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
<b>Note:</b> 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)"

@ -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"

31
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 "<span foreground=\"#cc241d\">$temps°C</span>")
icon=""
elif [ "$temps" -gt "50" ];then
temps=$(echo "<span foreground=\"#d79921\">$temps°C</span>")
icon=""
else
temps=$(echo "<span foreground=\"#98971a\">$temps°C</span>")
icon=""
fi
#echo "$temps"
printf "%s %s  %s\\n" "$icon" "$temps" "$fan"

@ -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"

13
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

@ -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"

@ -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
Loading…
Cancel
Save