~q3cpma/dotfiles

4bdd4c447c4913c93d36c0fb0854bd74bebfa8a0 — q3cpma 4 months ago 3526232
Update lemonbar to latest
M .config/lemonbar/cpu_usage.awk => .config/lemonbar/cpu_usage.awk +2 -3
@@ 8,12 8,11 @@ function stat_read()
	total = work + $4 + $5
}

BEGIN\
BEGIN \
{
	stat_read()
	while (1)
	while (sleep(delay))
	{
		sleep(delay)
		split($0, old)
		stat_read()
		usage = (work - work_prev) / (total - total_prev)

M .config/lemonbar/disk_usage.awk => .config/lemonbar/disk_usage.awk +3 -3
@@ 1,14 1,14 @@
BEGIN\
BEGIN \
{
	auto_unit_init()
	cmd = "df -k -- " mountpoint
	while (1)
	do
	{
		cmd | getline
		cmd | getline
		close(cmd)
		print "d" ($4 / $2 > high ? red : "") \
			auto_unit_ratio($3 * 2^10, $2 * 2^10, "%.1f / %.1f %s")
		sleep(delay)
	}
	while (sleep(delay))
}

M .config/lemonbar/hwmon_temp.awk => .config/lemonbar/hwmon_temp.awk +7 -19
@@ 1,25 1,13 @@
BEGIN\
BEGIN \
{
	label = gets(prefix "_label")
	if (!label)
		label = "temp"
	label = (label ? label : "temp")
	tmax = gets(prefix "_max")
	if (tmax)
	do
	{
		tmax /= 1000
		while (1)
		{
			tcur = gets(prefix "_input") / 1000
			printf "t%s: %s%d°C\n", label, (tcur > tmax ? red : ""), tcur
			sleep(delay)
		}
	}
	else
	{
		while (1)
		{
			printf "t%s: %d°C\n", label, gets(prefix "_input") / 1000
			sleep(delay)
		}
		tcur = gets(prefix "_input")
		printf "t%s: %s%d°C\n",
			label, (tmax && tcur > tmax ? red : ""), tcur / 1000 + 0.5
	}
	while (sleep(delay))
}

M .config/lemonbar/mem_usage.awk => .config/lemonbar/mem_usage.awk +3 -3
@@ 7,10 7,10 @@ function get_meminfo()
	close("/proc/meminfo")
}

BEGIN\
BEGIN \
{
	auto_unit_init()
	while (1)
	do
	{
		get_meminfo()
		total   = meminfo["MemTotal"]


@@ 21,6 21,6 @@ BEGIN\
		printf "m%s%.1f / %.1f GiB\n",
			(used / total > high ? red : ""),
			used / 2^20, total / 2^20
		sleep(delay)
	}
	while (sleep(delay))
}

A .config/lemonbar/mus_fmt.awk => .config/lemonbar/mus_fmt.awk +49 -0
@@ 0,0 1,49 @@
function value(line)
{
	sub("tag [^ ]+ ", "", line)
	return line
}
/^tag / {tag[$2] = value($0)}
END \
{
	# Remove /TOTAL from NUMBER tags
	sub("/.*$", "", tag["TRACKNUMBER"])
	# DISCNUMBER / DISCTOTAL
	if ("DISCNUMBER" in tag)
	{
		sub("/.*$", "", tag["DISCNUMBER"])
		if ("DISCTOTAL" in tag)
		{
			disc = sprintf(" (Disc %0" length(tag["DISCTOTAL"]) "d/%d)",
						   tag["DISCNUMBER"], tag["DISCTOTAL"])
		}
		else
		{
			disc = " (Disc " tag["DISCNUMBER"] ")"
		}
	}
	# TRACKNUMBER / TRACKTOTAL
	if ("TRACKTOTAL" in tag)
	{
		track = sprintf("%0" length(tag["TRACKTOTAL"]) "d/%d",
						tag["TRACKNUMBER"], tag["TRACKTOTAL"])
	}
	else
	{
		track = tag["TRACKNUMBER"]
	}
	# Various artists
	if ("ARTIST" in tag && tag["ARTIST"] != tag["ALBUMARTIST"])
	{
		various = " (" tag["ARTIST"] ")"
	}

	printf "%s - %s%s%s - %s. %s%s\n",
		("ALBUMARTIST" in tag ? tag["ALBUMARTIST"] : tag["ARTIST"]),
		("DATE" in tag ? "(" tag["DATE"] ") " : ""),
		tag["ALBUM"],
		disc,
		track,
		tag["TITLE"],
		various
}

M .config/lemonbar/mus_status.sh => .config/lemonbar/mus_status.sh +3 -53
@@ 2,59 2,9 @@
# Dependencies: mus, mbcut
# Portability:	POSIX
set -eu
cd -- "$(dirname -- "$0")"
. ./config

. "$(dirname -- "$0")"/config


format_status()
{
	awk '
		function value(line)
		{
			sub("tag [^ ]+ ", "", line)
			return line
		}

		/^tag / {tag[$2] = value($0)}

		END\
		{
			# Remove /TOTAL from NUMBER tags
			sub("/.*$", "", tag["TRACKNUMBER"])
			# DISCNUMBER / DISCTOTAL
			if("DISCNUMBER" in tag)
			{
				sub("/.*$", "", tag["DISCNUMBER"])
				if("DISCTOTAL" in tag)
				{
					disc = sprintf(" (Disc %0" length(tag["DISCTOTAL"]) "d/%d)", \
						tag["DISCNUMBER"], tag["DISCTOTAL"])
				}
				else
					disc = " (Disc " tag["DISCNUMBER"] ")"
			}
			# TRACKNUMBER / TRACKTOTAL
			if("TRACKTOTAL" in tag)
			{
				track = sprintf("%0" length(tag["TRACKTOTAL"]) "d/%d", \
					tag["TRACKNUMBER"], tag["TRACKTOTAL"])
			}
			else
				track = tag["TRACKNUMBER"]
			# Various artists
			if("ARTIST" in tag && tag["ARTIST"] != tag["ALBUMARTIST"])
				various = " (" tag["ARTIST"] ")"

			printf "%s - %s%s%s - %s. %s%s\n",
				("ALBUMARTIST" in tag ? tag["ALBUMARTIST"] : tag["ARTIST"]),
				("DATE" in tag ? "(" tag["DATE"] ") " : ""),
				tag["ALBUM"],
				disc,
				track,
				tag["TITLE"],
				various
		}'
}

read -r status
status=${status#status }


@@ 84,7 34,7 @@ case "$status" in
		buttons="$buttons %{A:mus_client TRACK_NEXT:}%{R}next%{R}%{A}"
		buttons="$buttons %{A:mus_client ALBUM_NEXT:}%{R}nextalbm%{R}%{A}"
		buttons="$buttons %{A:mus_client PL_EDIT:}"
		msg=$(mbcut -e "$(format_status)" $mus_maxlen | sed 's#%#%%#g')
		msg=$(mbcut -e "$(awk -f mus_fmt.awk)" $mus_maxlen | sed 's#%#%%#g')
		;;
	no_playlist|empty_playlist)
		color=$red

M .config/lemonbar/netrate.awk => .config/lemonbar/netrate.awk +8 -12
@@ 25,9 25,9 @@ function init_bar()

function update_bar()
{
	if(tics == barwidth)
	if (tics == barwidth)
	{
		# The blocks are 3 bytes unicode chars
		# The blocks are 3 bytes long when encoded as UTF-8
		rxbar = substr(rxbar, 4)
		txbar = substr(txbar, 4)
	}


@@ 41,13 41,10 @@ function update_bar()
	txbar = txbar barsym[min(7, int(txrate / txbarden))]
}

BEGIN\
BEGIN \
{
	if(rxmax == "" || txmax == "")
		die("rxmax and txmax variables must be set!")

	sysfspath = "/sys/class/net/" ifname
	if(system("test -e " sysfspath))
	if (system("test -e " sysfspath))
		die(sysfspath ": path doesn't exist")
	rxpath = sysfspath "/statistics/rx_bytes"
	txpath = sysfspath "/statistics/tx_bytes"


@@ 58,13 55,12 @@ BEGIN\
	auto_unit_init()
	init_bar()
	update_rate()
	while(1)
	while (sleep(delay))
	{
		sleep(delay);
		update_rate()
		update_bar()
		printf "n %s↓ %8s/s %s%%{F-} %s↑ %8s/s %s\n", \
			(rxrate > rxmax * high ? red : ""), auto_unit(rxrate, "%.0f %s"), rxbar, \
			(txrate > txmax * high ? red : ""), auto_unit(txrate, "%.0f %s"), txbar
		printf "n %s↓ %8s/s %s%%{F-} %s↑ %8s/s %s\n",
			(rxmax && rxrate > rxmax * high ? red : ""), auto_unit(rxrate, "%.0f %s"), rxbar,
			(txmax && txrate > txmax * high ? red : ""), auto_unit(txrate, "%.0f %s"), txbar
	}
}

M .config/lemonbar/util.awk => .config/lemonbar/util.awk +7 -7
@@ 21,7 21,7 @@ function log2(val)

function sleep(val)
{
	system("sleep " val)
	return system("sleep " val) == 0
}

function gets(path)


@@ 34,15 34,15 @@ function gets(path)

function auto_unit_init()
{
	unit_name[0]  = "B"
	unit_name[1]  = "KiB"
	unit_name[2]  = "MiB"
	unit_name[0] = "B"
	unit_name[1] = "KiB"
	unit_name[2] = "MiB"
	unit_name[3] = "GiB"
	unit_name[4] = "TiB"

	unit_den[0]	 = 1
	unit_den[1]	 = 2^10
	unit_den[2]	 = 2^20
	unit_den[0]	= 1
	unit_den[1]	= 2^10
	unit_den[2]	= 2^20
	unit_den[3] = 2^30
	unit_den[4] = 2^40
}