Add community scripts for i3blocks

remotes/origin/ubuntu-i3
Shaun Reed 4 years ago
parent 3233439d88
commit 3236629420

@ -0,0 +1,18 @@
# i3-blocks-contrib
A collection of useful blocks for [i3blocks](https://github.com/vivien/i3blocks), for the amazing [i3](https://i3wm.org) window manager.
## Configuration
Some examples on how to configure these in your `i3blocks` config file:
- @rosshadden's [i3blocks.conf](https://github.com/rosshadden/dotfiles/blob/master/src/.config/i3/i3blocks.conf)
- @oppenlander's [i3blocks.conf](https://github.com/oppenlander/dotfiles/blob/master/i3/i3blocks.conf)
## Contributing
As hinted by the name, this is intended to be openly contributed to by the community.
There is no official contributing guide, but please try to fit in to the style and themes found in our existing blocks.
We use a somewhat ad-hock [YUIDoc](http://yui.github.io/yuidoc/) documentation syntax.

@ -0,0 +1,35 @@
#!/bin/bash
################################
# Shows bandwidth
#
# @param {String(tx|rx)} type: The bandwidth type to check
# @return {Number(kB/s)}: Speed of the interface
################################
dir=$(dirname $0)
source $dir/util.sh
type=$BLOCK_INSTANCE
file=/tmp/i3blocks_bandwidth_$type
touch $file
prev=$(cat $file)
cur=0
netdir=/sys/class/net
for iface in $(ls -1 $netdir); do
# Skip the loopback interface
if [ "$iface" == "lo" ]; then continue; fi
f=$netdir/$iface/statistics/${type}_bytes
n=$(cat $f)
cur=$(expr $cur + $n)
done
delta=$(calc "$cur - $prev")
echo "$(calc "$delta / 1000") kB/s"
# store result
echo $cur > $file

@ -0,0 +1,42 @@
#!/usr/bin/env bash
################################
# Shows info about connected batteries.
#
# Dependencies:
# - acpi
#
# @return {Number(%)}: Current battery charge
################################
dir=$(dirname $0)
source $dir/util.sh
full=""
short=""
status=0
# Exit if no battery was found
if [ "$(acpi)" == "" ]; then exit 0; fi
state=$(acpi | sed -n 's/Battery [0-9]: \([A-Z]\).*, .*/\1/p')
chg=$(acpi | sed -n 's/Battery [0-9]:.*, \([0-9]\{1,3\}\)%.*/\1/p')
# Charging or Unknown
if [ $state = "C" ] || [ $state = "U" ]; then
icon=""
else
if [ $chg -le 10 ]; then
icon=""
status=33
else
icon=""
fi
fi
full="$icon $chg%"
short="$chg%"
echo $full
echo $short
exit $status

@ -0,0 +1,44 @@
#!/usr/bin/env bash
################################
# Shows AUR packages that need updated.
#
# Dependencies:
# - checkupdates
# - bauerbill
# - [notify-send]
#
# @return {Number}: Outdated packages
################################
dir=$(dirname "$0")
source $dir/util.sh
full=""
short=""
status=0
archPackages=$(checkupdates)
allPackages=$(bauerbill -Quq --aur)
numArchPackages=$(numLines "$archPackages")
numAllPackages=$(numLines "$allPackages")
numAurPackages=$(calc "$numAllPackages - $numArchPackages")
if [ "$numAllPackages" -le "$numArchPackages" ]; then
numAurPackages=$numAllPackages
fi
full=$numAurPackages
short=$full
case $BLOCK_BUTTON in
# right click: show packages
3)
aurPackages=$(diff -y <(echo "$archPackages") <(echo "$allPackages") | awk -p '{ print $3 }')
notify-send "AUR packages" "$aurPackages"
;;
esac
echo $full
echo $short
exit $status

@ -0,0 +1,26 @@
#!/usr/bin/env bash
################################
# Shows current brightness
#
# dependencies:
# - xbacklight
#
# @return {Number}: Current brightness
################################
case $BLOCK_BUTTON in
# right click
# set to `20
3) xbacklight -set 20 ;;
# scroll up
# raise brightness
4) xbacklight -inc 10 ;;
# scroll down
# lower brightness
5) xbacklight -dec 10 ;;
esac
printf "%.0f" "$(xbacklight -get)"

@ -0,0 +1,47 @@
#!/usr/bin/env bash
################################
# Shows info about the CPU
#
# Dependencies:
# - [notify-send]
#
# @return {Number(%)}: CPU usage
################################
dir=$(dirname $0)
source $dir/util.sh
full=""
short=""
status=0
read cpu a b c previdle rest < /proc/stat
prevtotal=$(calc "$a + $b + $c + $previdle")
sleep 0.5
read cpu a b c idle rest < /proc/stat
total=$(calc "$a + $b + $c + $idle")
CPU=$(calc "100 * (($total - $prevtotal) - ($idle - $previdle)) / ($total - $prevtotal)")
full="$CPU%"
short=$full
if [ $CPU -ge 90 ]; then
status=33
fi
case $BLOCK_BUTTON in
# right click: show packages
3)
n=16
summary=$(ps -eo pcpu,pmem,pid,comm --sort=-pcpu | head -$n)
notify-send "Top $n CPU-eaters" "$summary"
;;
esac
echo $full
echo $short
exit $status

@ -0,0 +1,13 @@
#!/usr/bin/env bash
################################
# Shows current date
#
# @param {String} format: The format of the date
# @return {Date}: Current date
################################
format=${BLOCK_INSTANCE:-"%Y-%m-%d"}
date +"$format"
date +"%m-%d"

@ -0,0 +1,68 @@
#!/usr/bin/env bash
################################
# Shows info about a specified mount point
#
# Dependencies:
# - [notify-send]
#
# @param {String} disk: The mount point to check
# @return {Number(%)}: Space used on the disk
################################
dir=$(dirname $0)
source $dir/util.sh
full=""
short=""
status=0
disks=$(lsblk | tail -n +2 | awk '{ print $7 }' | sed '/^\s*$/d' | sort)
let numDisks=$(echo "$disks" | wc -l)
let diskNum=$(getCache 1)
getDisk() {
echo "$disks" | sed -n "$diskNum p"
}
disk=$(getDisk)
case $BLOCK_BUTTON in
# right click: show details
# TODO: fix
3)
local summary=$(du -h --max-depth=1 $disk)
notify-send "Disk usage" "$summary"
;;
# scroll up: cycle disks
4)
diskNum=$[$(getCache) - 1]
if (( diskNum <= 0 )); then
diskNum=$numDisks
fi
setCache $diskNum
disk=$(getDisk)
;;
5)
# scroll down: cycle disks
diskNum=$[$(getCache) + 1]
if (( diskNum >= numDisks + 1 )); then
diskNum=1
fi
setCache $diskNum
disk=$(getDisk)
;;
esac
usage=$(df -h $disk | sed -n '2 p')
usage=($usage)
if [ ${usage[4]%?} -ge 90 ]; then
status=33
fi
full="$disk ${usage[4]}"
short="$full"
echo $full
echo $short
exit $status

@ -0,0 +1,31 @@
#!/usr/bin/env bash
################################
# Shows current keyboard layout.
# Allows layout toggling.
#
# Dependencies:
# - [Ross' key script](https://github.com/rosshadden/dotfiles/blob/master/src/lib/keys.sh)
#
# @return {String}: Current keyboard layout
################################
keys=$HOME/bin/keys
full=""
short=""
status=0
case $BLOCK_BUTTON in
# right click: toggle key variant
3) $keys toggle ;;
esac
layout=$($keys get)
full=$layout
short=${layout:0:1}
echo $full
echo $short
exit $status

@ -0,0 +1,46 @@
#!/usr/bin/env bash
################################
# Shows info about the RAM
#
# Dependencies:
# - [notify-send]
#
# @return {Number(%)}: RAM usage
################################
dir=$(dirname $0)
source $dir/util.sh
full=""
short=""
status=0
exec 6< /proc/meminfo
read a total b <&6
read a free b <&6
read a b c <&6
read a buffer b <&6
read a cached b <&6
MEM=$(calc "100 * ($total - ($free + $buffer + $cached)) / $total")
full="$MEM%"
short=$full
if [ $MEM -ge 80 ]; then
status=33
fi
case $BLOCK_BUTTON in
# right click: show packages
3)
n=16
summary=$(ps -eo pmem,pcpu,pid,comm --sort=-pmem | head -$n)
notify-send "Top $n RAM-eaters" "$summary"
;;
esac
echo $full
echo $short
exit $status

@ -0,0 +1,38 @@
#!/usr/bin/env bash
################################
# Shows info from media players.
#
# Dependencies:
# - mpc
#
# @return {String}: Current media info
################################
full=""
short=""
status=0
format=${BLOCK_INSTANCE:-'[[%artist% - ]%title%[ \[%album%\]]]|[%file%]'}
current=$(mpc current)
currentLong=$(mpc current -f "$format")
state=playing
if [[ "$current" ]]; then
# Make icon mapping
declare -A icons
icons["playing"]=""
icons["paused"]=""
icons["stopped"]=""
# Determine which icon to use
icon=${icons[$state]}
full="$currentLong $icon"
short="$current $icon"
fi
echo "$full"
echo "$short"
exit "$status"

@ -0,0 +1,36 @@
#!/usr/bin/env bash
################################
# Shows IP address of a given interface
#
# @param {String} interface: The network interface to check
# @return {String(IP)}: IP address of the interface
################################
dir=$(dirname $0)
source "$dir/util.sh"
full=""
short=""
status=0
interface=${BLOCK_INSTANCE:-eth0}
netPath=/sys/class/net
interfacePath=$(echo $netPath/$interface)
# Expand wildcard interfaces
interface=${interfacePath#$netPath/}
state=$(cat $interfacePath/operstate)
if [ $state == "up" ]; then
ips=$(ip addr show $interface | perl -n -e'/inet (.+)\// && print $1')
ip=${ips:-0.0.0.0}
full=$ip
short=$full
fi
echo "$full"
echo "$short"
exit $status

@ -0,0 +1,34 @@
#!/usr/bin/env bash
################################
# Shows pacman packages that need updated.
#
# dependencies:
# - checkupdates
# - [notify-send]
#
# @return {Number}: Outdated packages
################################
dir=$(dirname "$0")
source $dir/util.sh
full=""
short=""
status=0
packages=$(checkupdates)
numPackages=$(numLines "$packages")
full=$numPackages
short=$full
echo "$full"
echo "$short"
case $BLOCK_BUTTON in
# right click: show packages
3) notify-send "Pacman packages" "$packages" ;;
esac
exit $status

@ -0,0 +1,50 @@
#!/usr/bin/env bash
################################
# Shows info from media players.
#
# TODO: make output format configurable
#
# Dependencies:
# - playerctl
#
# @return {String}: Current media info
################################
dir=$(dirname $0)
source $dir/util.sh
full=""
short=""
status=0
# Exit if no player found
players=$(playerctl -l)
if [[ ! $players ]]; then exit 0; fi
artist=$(playerctl metadata artist)
title=$(playerctl metadata title)
album=$(playerctl metadata album)
state=$(playerctl status)
if [[ "$title" ]]; then
# Make icon mapping
declare -A icons
icons["Playing"]=""
icons["Paused"]=""
icons["Stopped"]=""
# Determine which icon to use
icon=${icons[$state]}
full="$title"
if [[ "$artist" ]]; then full="$artist - $full"; fi
short="$full $icon"
if [[ "$album" ]]; then full="$full [$album]"; fi
full="$full $icon"
fi
echo $full
echo $short
exit $status

@ -0,0 +1,71 @@
#!/usr/bin/env bash
################################
# Shows info about sound/volume.
# Allows simple volume controls.
#
# Thanks to [@EliteTK](https://gist.github.com/EliteTK/36d061fa24372fb70312),
# for the big speed gain when switching to `ponymix`
#
# Dependencies:
# - ponymix
# - ttf-font-icons
#
# @return {Number}: Current volume
################################
dir=$(dirname $0)
source $dir/util.sh
full=""
short=""
status=0
step=${BLOCK_INSTANCE:-5}
getVolume() {
ponymix get-volume
}
isMuted() {
ponymix is-muted
}
case $BLOCK_BUTTON in
# right click
# mute/unmute
3) ponymix toggle >/dev/null ;;
# scroll up
# raise volume
4) ponymix increase $step >/dev/null ;;
# scroll down
# lower volume
5) ponymix decrease $step >/dev/null ;;
esac
vol=$(getVolume)
# level-based icon
if (( $vol == 0 )); then
icon=""
elif (( $vol < 34 )); then
icon=""
elif (( $vol < 67 )); then
icon=""
else
icon=""
fi
# determine mute status
if isMuted; then
status=33
fi
full="$icon $vol%"
short=$vol
echo $full
echo $short
exit $status

@ -0,0 +1,13 @@
#!/usr/bin/env bash
################################
# Shows current time
#
# @param {String} format: The format of the time
# @return {Time}: Current time
################################
format=${BLOCK_INSTANCE:-"%H:%M:%S"}
date +"$format"
date +"%H:%M"

@ -0,0 +1,41 @@
################################
# Calculates a given expression
#
# Dependencies:
# - bc
#
# @param {String} 1: The expression to calculate
# @return {Number}: The result of the expression
################################
calc() {
echo "$1" | bc
}
################################
# Counts lines in text, accounting for empty values
#
# @param {String} 1: The input text
# @return {Number}: The number of lines
################################
numLines() {
if [[ "$1" == "" ]]; then
echo 0
else
echo "$1" | wc -l
fi
}
cacheDir=".cache"
cacheFile="$cacheDir/i3-blocks-contrib-${BLOCK_NAME}"
if [[ -z $cacheDir ]]; then
mkdir $cacheDir
fi
getCache() {
cat $cacheFile || echo $1
}
setCache() {
echo "$1" > $cacheFile
}

@ -0,0 +1,49 @@
#!/usr/bin/env bash
################################
# Shows info about the weather (in Cincinnati) from accuweather.com
#
# TODO: completely rewrite, probably using openweather APIs
# TODO: make location configurable
# TODO: make temperature unit configurable
#
# @return {Number(degrees Fahrenheit)}: Current temperature in Cincinnati
################################
dir=$(dirname $0)
source $dir/util.sh
full=""
short=""
status=0
URL='http://www.accuweather.com/en/us/cincinnati-oh/45212/weather-forecast/350126'
SITE="$(curl -s "$URL")"
weather="$(echo "$SITE" | awk -F\' '/acm_RecentLocationsCarousel\.push/{print $13 }'| head -1)"
temp="$(echo "$SITE" | awk -F\' '/acm_RecentLocationsCarousel\.push/{print $10 }'| head -1)"
if [[ $weather == *thunder* || $weather == *Thunder* ]]; then
icon=""
else
if [[ $weather == *rain* || $weather == *Rain* ]]; then
icon=""
else
if [[ $weather == *snow* || $weather == *Snow* ]]; then
icon="❄"
else
if [[ $weather == *cloud* || $weather == *Cloud* ]]; then
icon=""
else
icon=""
fi
fi
fi
fi
full="$icon $temp°"
short="$temp°"
echo $full
echo $short
exit $status

@ -0,0 +1,44 @@
#!/usr/bin/env bash
################################
# Shows AUR packages that need updated.
#
# Dependencies:
# - checkupdates
# - yaourt
# - [notify-send]
#
# @return {Number}: Outdated packages
################################
dir=$(dirname $0)
source $dir/util.sh
full=""
short=""
status=0
archPackages=$(checkupdates)
allPackages=$(yaourt -Quaq)
numArchPackages=$(numLines "$archPackages")
numAllPackages=$(numLines "$allPackages")
numAurPackages=$(calc "$numAllPackages - $numArchPackages")
if [ $numAllPackages -le $numArchPackages ]; then
numAurPackages=$numAllPackages
fi
full=$numAurPackages
short=$full
case $BLOCK_BUTTON in
# right click: show packages
3)
aurPackages=$(diff -y <(echo "$archPackages") <(echo "$allPackages") | awk -p '{ print $3 }')
notify-send "AUR packages" "$aurPackages"
;;
esac
echo $full
echo $short
exit $status
Loading…
Cancel
Save