commit 0eefa95e352d3867cacd864621545bd0c673cda0
parent 095f539bbb36a47f2492d036947233b1c915e055
Author: Oscar Benedito <oscar@oscarbenedito.com>
Date:   Wed, 22 Dec 2021 21:05:09 +0100

Add personal config

Diffstat:
MMakefile | 9++++++++-
Abin/dwmb-backlight | 3+++
Abin/dwmb-backups | 26++++++++++++++++++++++++++
Abin/dwmb-battery2 | 90+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Abin/dwmb-date | 3+++
Abin/dwmb-disk | 4++++
Abin/dwmb-torrents | 13+++++++++++++
Abin/dwmb-updates | 7+++++++
Abin/dwmb-volume | 27+++++++++++++++++++++++++++
Aconfig.h | 17+++++++++++++++++
10 files changed, 198 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile @@ -2,16 +2,23 @@ PREFIX ?= /usr/local CC ?= cc LDFLAGS = -lX11 +binsrc = $(wildcard bin/*) +binobj = $(patsubst %,$(DESTDIR)$(PREFIX)/%,$(binsrc)) + dwmblocks: dwmblocks.c config.h ${CC} dwmblocks.c $(LDFLAGS) -o dwmblocks config.h: cp config.def.h $@ -install: dwmblocks +install: dwmblocks $(binobj) mkdir -p $(DESTDIR)$(PREFIX)/bin install -m 0755 dwmblocks $(DESTDIR)$(PREFIX)/bin/dwmblocks +$(DESTDIR)$(PREFIX)/%: % + mkdir -p $(DESTDIR)$(PREFIX)/bin + install -m 0755 $< $@ + uninstall: rm -f $(DESTDIR)$(PREFIX)/bin/dwmblocks diff --git a/bin/dwmb-backlight b/bin/dwmb-backlight @@ -0,0 +1,3 @@ +#!/bin/sh + +echo " $(xbacklight -get)%" | sed "s/\.[0-9]*//g" diff --git a/bin/dwmb-backups b/bin/dwmb-backups @@ -0,0 +1,26 @@ +#!/bin/sh + +outfile="/home/oscar/.local/share/backups" + +if [ ! -f "$outfile" ]; then + lastdate="0" + lasterr="0" +else + tmp="$(cat "$outfile")" + lastdate="${tmp%% *}" + lasterr="${tmp##* }" +fi + +if [ "$(date --date="12 hours ago" +%s)" -ge "$lastdate" ]; then + echo "" + restic-daily > /dev/null & + exit 0 +else + if [ "$lasterr" = "0" ]; then + exit 0 + elif [ "$lasterr" = "2" ] && [ "$lastdate" -ge "$(date --date="20 mins ago" +%s)" ]; then + echo "" + else + echo "" + fi +fi diff --git a/bin/dwmb-battery2 b/bin/dwmb-battery2 @@ -0,0 +1,90 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2016 James Murphy +# Licensed under the GPL version 2 only +# +# A battery indicator blocklet script for i3blocks + +import re +from subprocess import check_output + +status = check_output(['acpi'], universal_newlines=True) + +if not status: + # stands for no battery found + fulltext = "\uf00d \uf240" + percentleft = 100 +else: + # if there is more than one battery in one laptop, the percentage left is + # available for each battery separately, although state and remaining + # time for overall block is shown in the status of the first battery + batteries = status.split("\n") + state_batteries=[] + commasplitstatus_batteries=[] + percentleft_batteries=[] + time = "" + for battery in batteries: + if battery!='': + state_batteries.append(battery.split(": ")[1].split(", ")[0]) + commasplitstatus = battery.split(", ") + if not time: + time = commasplitstatus[-1].strip() + # check if it matches a time + time = re.match(r"(\d+):(\d+)", time) + if time: + time = ":".join(time.groups()) + timeleft = " ({})".format(time) + else: + timeleft = "" + + p = int(commasplitstatus[1].rstrip("%\n")) + if p>0: + percentleft_batteries.append(p) + commasplitstatus_batteries.append(commasplitstatus) + state = state_batteries[0] + commasplitstatus = commasplitstatus_batteries[0] + if percentleft_batteries: + percentleft = int(sum(percentleft_batteries)/len(percentleft_batteries)) + else: + percentleft = 0 + + # stands for charging + FA_LIGHTNING = "\uf0e7" + + # stands for plugged in + FA_PLUG = "\uf1e6" + + # stands for using battery + FA_BATTERY_0 = "\uf244" # 0/4 + FA_BATTERY_1 = "\uf243" # 1/4 + FA_BATTERY_2 = "\uf242" # 2/4 + FA_BATTERY_3 = "\uf241" # 3/4 + FA_BATTERY_4 = "\uf240" # 4/4 + + # stands for unknown status of battery + FA_QUESTION = "\uf128" + + + if state == "Discharging": + if percentleft <= 10: + fulltext = FA_BATTERY_0 + " " + elif percentleft < 35: + fulltext = FA_BATTERY_1 + " " + elif percentleft < 65: + fulltext = FA_BATTERY_2 + " " + elif percentleft < 90: + fulltext = FA_BATTERY_3 + " " + else: + fulltext = FA_BATTERY_4 + " " + elif state == "Full": + fulltext = FA_PLUG + " " + timeleft = "" + elif state == "Unknown": + fulltext = FA_BATTERY_0 + " " + FA_QUESTION + " " + timeleft = "" + else: + fulltext = FA_LIGHTNING + " " + + fulltext += str(percentleft) + "%" + timeleft + +print(fulltext) diff --git a/bin/dwmb-date b/bin/dwmb-date @@ -0,0 +1,3 @@ +#!/bin/sh + +date +"%b %d, %H:%M" diff --git a/bin/dwmb-disk b/bin/dwmb-disk @@ -0,0 +1,4 @@ +#!/bin/sh + +#echo -n " "; df -h -l --output='used' "$HOME" | grep -E -o '[0-9\.]+G' +echo -n " "; df -h -l --output='avail' "$HOME" | tail -n 1 | cut -d" " -f 3 diff --git a/bin/dwmb-torrents b/bin/dwmb-torrents @@ -0,0 +1,13 @@ +#!/bin/sh + +transmission-remote -l | grep "%\|n/a" | + sed " # The letters are for sorting and will not appear. + s/.*Idle.*/B /; + s/.*Queued.*/C /; + s/.*Stopped.*/D /; + s/.*Uploading.*/E /; + s/.*Seeding.*/F /; + s/.*100%.*/G /; + s/.*%.*/A /; + s/.*Downloading.*/A /" | + sort -h | uniq -c | awk '{print $3, $1}' | paste -sd ' ' - diff --git a/bin/dwmb-updates b/bin/dwmb-updates @@ -0,0 +1,7 @@ +#!/bin/sh + +UPDATES="$(checkupdates | wc -l)" +if [ "0" != "$UPDATES" ]; then + echo " $UPDATES" + sudo checkupdates -d >/dev/null 2>&1 & +fi diff --git a/bin/dwmb-volume b/bin/dwmb-volume @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +# Displays the default device, volume, and mute status for i3blocks + + +AUDIO_HIGH_SYMBOL="" +AUDIO_MED_SYMBOL="" +AUDIO_LOW_SYMBOL="" +AUDIO_MUTED_SYMBOL="" + +AMIXER=$(amixer get Master | tail -n 1) # get last line of amixer output + +# show either volume or mute +if [[ $AMIXER =~ "[on]" ]]; then # check if channel is muted by checking if line contains the word "on" + IFS=' ' read -ra args <<< "$AMIXER" # split string + + VOL="${args[4]:1:-2}" # get 4th argument (the volume) from the string we just split and remove the first and last argument (square brackets) and the % at the end + + if [ "$VOL" -le "0" ]; then + echo "$AUDIO_LOW_SYMBOL" + elif [ "$VOL" -le "50" ]; then + echo "$AUDIO_MED_SYMBOL $VOL%" + else + echo "$AUDIO_HIGH_SYMBOL $VOL%" + fi +else + echo "$AUDIO_MUTED_SYMBOL" +fi diff --git a/config.h b/config.h @@ -0,0 +1,17 @@ +/* modify this file to change what commands output to your statusbar, and + * recompile using the make command */ +static const Block blocks[] = { + /* command interval signal */ + { "dwmb-disk", 30, 0 }, + { "dwmb-backups", 3600, 5 }, + { "dwmb-updates", 3600, 4 }, + { "dwmb-backlight", 0, 2 }, + { "dwmb-volume", 0, 1 }, + { "dwmb-torrents", 30, 3 }, + { "dwmb-battery2", 30, 0 }, + { "dwmb-date", 1, 0 }, +}; + +/* sets delimeter between status commands. NULL character ('\0') means no + * delimeter */ +static char delim[] = " | ";