💾 Archived View for dots.omarpolo.com › config › herbstluftwm › process.awk.gmi captured on 2024-05-26 at 14:35:35. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2022-04-28)

-=-=-=-=-=-=-

process.awk

This awk script processes the events generated by `event-gen' and outputs the text of the bar for dzen2. It needs some variable to be defined on the command line, see `panel'.

BEGIN {
	visible = true
}

/^tag/ {
	cmd = sprintf("herbstclient tag_status %s", monitor)
	cmd | getline
	for (i = 1; i <= NF; i++) {
		tags[i] = $i
	}
	close(cmd)
}

/^date/ {
	$1 = ""
	date = substr($0, 2)
}

/^quit_panel/ {
	exit 0
}

/^reload/ {
	exit 0
}

/^focus_changed/ || /^window_title_changed/ {
	$1 = ""
	$2 = ""
	windowtitle = substr($0, 3)
}

/^play/ || /^next/ || /^prev/ {
	cmd = "amused status"
	cmd | getline
	$1 = ""
	file = substr($0, 2)
	close(cmd)

	# poor man basename
	player = gensub(".*/", "", 1, file)
	# and strip out the extension
	player = gensub("\.[A-Za-z0-9]+$", "", 1, player)
}

{
	for (i = 1; i <= length(tags); i++) {
		t = tags[i]
		if (t ~ "^#") {
			printf("^bg(%s)^fg(%s)", selbg, selfg)
		} else if (t ~ "^\\+") {
			printf "^bg(#9CA668)^fg(#141414)"
		} else if (t ~ "^:") {
			printf "^bg()^fg(#222222)"
		} else if (t ~ "^!") {
			printf "^bg(#FF0675)^fg(#141414)"
		} else {
			printf "^bg()^fg(#d6d6d6)"
		}

		printf(" %s ^bg()^fg()", substr(t, 2))
	}

	printf("| %s ", date);

	if (player != "") {
		printf("| %s ", player);
	}

	printf("| %s ", windowtitle)

	printf("\n", right)
	fflush()
	next
}