diff --git a/.config/i3blocks/battery b/.config/i3blocks/battery new file mode 100755 index 0000000..816a9fd --- /dev/null +++ b/.config/i3blocks/battery @@ -0,0 +1,21 @@ +#!/bin/bash +set -euo pipefail + +BATTERY=/sys/class/power_supply/BAT0 + +ac_conn=0 + +for ac in $(find /sys/class/power_supply -type l -name 'A*'); do + [ $(cat "${ac}/online") -eq 1 ] && ac_conn=1 +done + +bat_cap=() +for bat in $(find /sys/class/power_supply -type l -name 'B*'); do + bat_cap+="$(cat "${bat}/capacity")%" +done + +if [ ${ac_conn} -eq 0 ]; then + printf '\uf58d %s' ${bat_cap[@]} +else + printf '\uf740 %s' ${bat_cap[@]} +fi diff --git a/.config/i3blocks/config b/.config/i3blocks/config new file mode 100644 index 0000000..31c9218 --- /dev/null +++ b/.config/i3blocks/config @@ -0,0 +1,67 @@ +# i3blocks config file +# +# Please see man i3blocks for a complete reference! +# The man page is also hosted at http://vivien.github.io/i3blocks +# +# List of valid properties: +# +# align +# color +# command +# full_text +# instance +# interval +# label +# min_width +# name +# separator +# separator_block_width +# short_text +# signal +# urgent + +# Global properties +# +# The top properties below are applied to every block, but can be overridden. +# Each block command defaults to the script name to avoid boilerplate. +command=$HOME/.config/i3blocks/$BLOCK_NAME +separator_block_width=15 +markup=none + + +[disk] +interval=30 + +[volume] +interval=1 + +[dropbox] +interval=30 + +[keyboard] +interval=2 + +[mem] +interval=30 + +[load] +interval=30 + +[wifi] +interval=30 + +[battery] +interval=30 + +[temp] +interval=10 + +[time] +interval=1 +separator=false +separator_block_width=30 + + +[empty] +command=echo " " +interval=once diff --git a/.config/i3blocks/disk b/.config/i3blocks/disk new file mode 100755 index 0000000..a0e6a3b --- /dev/null +++ b/.config/i3blocks/disk @@ -0,0 +1,54 @@ +#!/usr/bin/env python + +import subprocess +import sys + +CRIT = 90.0 +MOUNT_BLACKLIST = ['/dev', '/efi', '/proc', '/run', '/sys', '/tmp'] + + +def main(): + output = subprocess.check_output([ + 'sh', '-c', 'df -a -B 1 | awk \'{ printf "%s\\t%d\\t%d\\n", $6, $2, $4 }\'' + ]).decode('utf-8') + + fs = {} + for line in output.split('\n'): + if len(line) == 0 or line[0] != '/': + continue + (mountpoint, total, available) = line.split('\t') + fs[mountpoint] = (total, available) + + color = '' + + strings = [] + for mount, data in fs.items(): + skip = False + for b in MOUNT_BLACKLIST: + if mount.startswith(b): + skip = True + + if skip: + continue + + usage = 0.0 + if float(data[0]) > 0.0: + usage = (1 - float(data[1])/float(data[0])) * 100.0 + + strings.append('{}: {:.0f}%'.format( + mount, + usage, + )) + + if usage > CRIT: + color = '#dd0000' + + print('\ufaed '+'\n'.join([ + ' '.join(strings), + ' '.join(strings), + color, + ])) + + +if __name__ == '__main__': + main() diff --git a/.config/i3blocks/dropbox b/.config/i3blocks/dropbox new file mode 100755 index 0000000..462b05b --- /dev/null +++ b/.config/i3blocks/dropbox @@ -0,0 +1,5 @@ +#!/bin/bash + +printf '\uf6e2 ' + +${HOME}/bin/dropbox.py status | head -n1 || true diff --git a/.config/i3blocks/keyboard b/.config/i3blocks/keyboard new file mode 100755 index 0000000..dcc94d7 --- /dev/null +++ b/.config/i3blocks/keyboard @@ -0,0 +1,10 @@ +#!/bin/bash + +which getxkblayout >/dev/null 2>/dev/null || { + printf '\uf071 getxkblayout package missing' + exit 1 +} + +printf '\uf812 ' + +getxkblayout | awk '/short/{ print $2 }' diff --git a/.config/i3blocks/load b/.config/i3blocks/load new file mode 100755 index 0000000..eac0b8c --- /dev/null +++ b/.config/i3blocks/load @@ -0,0 +1,5 @@ +#!/bin/bash + +printf '\uf085 ' + +uptime | sed 's/.*average: //' diff --git a/.config/i3blocks/mem b/.config/i3blocks/mem new file mode 100755 index 0000000..e70f80b --- /dev/null +++ b/.config/i3blocks/mem @@ -0,0 +1,5 @@ +#!/bin/bash + +printf '\uf85a ' + +free | awk '/Mem:/{ printf "%.0f%", (($2 - $7) / $2) * 100 }' diff --git a/.config/i3blocks/temp b/.config/i3blocks/temp new file mode 100755 index 0000000..0fbd795 --- /dev/null +++ b/.config/i3blocks/temp @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +import re +import subprocess + +CRIT = 70.0 + + +def main(): + sensors = subprocess.check_output(['sensors', '-u']).decode('utf-8') + + max_temp = 0.0 + for line in sensors.split('\n'): + if not re.match(r'.*temp._input:.*', line): + continue + temp = float(line.split(':')[1]) + + if temp > max_temp: + max_temp = temp + + text = '\uf2c7 {:.1f}°C'.format(max_temp) + color = '' + + if max_temp > CRIT: + color = '#dd0000' + + print('\n'.join([ + text, + text, + color, + ])) + + +if __name__ == '__main__': + main() diff --git a/.config/i3blocks/time b/.config/i3blocks/time new file mode 100755 index 0000000..d1692c5 --- /dev/null +++ b/.config/i3blocks/time @@ -0,0 +1,5 @@ +#!/bin/bash + +printf '\uf5ec ' + +date "+%Y-%m-%d %H:%M:%S" diff --git a/.config/i3blocks/volume b/.config/i3blocks/volume new file mode 100755 index 0000000..3ab0d55 --- /dev/null +++ b/.config/i3blocks/volume @@ -0,0 +1,28 @@ +#!/usr/bin/env python + +import subprocess + + +def main(): + volume = subprocess.check_output([ + 'pulsemixer', '--get-volume', + ]).decode('utf-8').strip().split(' ') + minvol = min([int(i) for i in volume]) + + mute = int(subprocess.check_output([ + 'pulsemixer', '--get-mute', + ]).decode('utf-8').strip()) == 1 + + icon = '\uf9c3' if mute else '\uf9c2' + text = '{} {}%'.format(icon, minvol) + color = '#7f7f7f' if mute else '' + + print('\n'.join([ + text, + text, + color, + ])) + + +if __name__ == '__main__': + main() diff --git a/.config/i3blocks/wifi b/.config/i3blocks/wifi new file mode 100755 index 0000000..c17ffc6 --- /dev/null +++ b/.config/i3blocks/wifi @@ -0,0 +1,18 @@ +#!/bin/bash + +interface=$(ip a | grep 'wlp.*:' | sed -E 's/^[0-9]*: ([^:]+):.*/\1/') + +# We found no wlp* interface: Get out here +[ -z "${interface}" ] && exit + +ip=$(ip a show ${interface} | awk '/inet .* scope global/{ print $2 }' | cut -d '/' -f1) + +# We found no ip: Get out here +[ -z "${ip}" ] && exit + +network=$(iwgetid -r) + +# We found no network: Get out here +[ -z "${network}" ] && exit + +printf "\uf1eb %s (%s)" ${network} ${ip}