Conky: Add a bunch of switches to gen.sh
That I'll never use
This commit is contained in:
		@@ -18,8 +18,11 @@ set -e
 | 
			
		||||
declare -r _name="$(basename -- "$0")"
 | 
			
		||||
# Options
 | 
			
		||||
declare _optout="${XDG_CONFIG_HOME:-$HOME/.config}/conky/conky.conf"
 | 
			
		||||
declare -i _optbar=1
 | 
			
		||||
declare -i _optgraph=1
 | 
			
		||||
declare -i _opthelp
 | 
			
		||||
declare -i _optverbose
 | 
			
		||||
declare -i _opttopitems=4
 | 
			
		||||
# Working variables
 | 
			
		||||
declare -a _args
 | 
			
		||||
declare _return
 | 
			
		||||
@@ -78,7 +81,10 @@ Generate a conky.conf configuration file in the current directory
 | 
			
		||||
 | 
			
		||||
  -o			Specify output file. Defaults to
 | 
			
		||||
			~/.config/conky/conky.conf
 | 
			
		||||
  -b			Hide bars
 | 
			
		||||
  -g			Hide graphs
 | 
			
		||||
  -h			Print this help text
 | 
			
		||||
  -t			Number of items to print in top lists. Defaults to 4
 | 
			
		||||
  -v			Print more status messages. Stacks
 | 
			
		||||
 | 
			
		||||
Copyright (c) 2020 rehashedsalt@cock.li
 | 
			
		||||
@@ -150,7 +156,6 @@ conky.config = {
 | 
			
		||||
EOF
 | 
			
		||||
}
 | 
			
		||||
step_text() {
 | 
			
		||||
	local -r topitems=4
 | 
			
		||||
	local -r nproc="$(nproc)"
 | 
			
		||||
	# Generate our actual functional Conky stuff
 | 
			
		||||
	# Header
 | 
			
		||||
@@ -166,44 +171,46 @@ step_text() {
 | 
			
		||||
	${color3}$hr$color
 | 
			
		||||
	${font Roboto:style=Medium:size=9}CPU$font: $freq_g GHz$alignr$cpu%
 | 
			
		||||
	EOF
 | 
			
		||||
	local gpl=1
 | 
			
		||||
	if (( nproc <= 2 )); then
 | 
			
		||||
		gpl=1
 | 
			
		||||
	elif (( nproc <= 4 )); then
 | 
			
		||||
		gpl=2
 | 
			
		||||
	elif (( nproc <= 8 )); then
 | 
			
		||||
		gpl=4
 | 
			
		||||
	else
 | 
			
		||||
		gpl=8
 | 
			
		||||
	fi
 | 
			
		||||
	local width=$(( 400 / gpl ))
 | 
			
		||||
	log "Generating $gpl graphs per row of CPU core stats" 1
 | 
			
		||||
	log "Graphs will be $width wide" 2
 | 
			
		||||
	local cpuinfo
 | 
			
		||||
	for i in $(seq 1 "$gpl" "$nproc"); do
 | 
			
		||||
		# Generate lines
 | 
			
		||||
		local line
 | 
			
		||||
		for j in $(seq 0 $(( gpl - 1 ))); do
 | 
			
		||||
			# Generate graphs
 | 
			
		||||
			local cpu=$(( i + j ))
 | 
			
		||||
			log "Generating graph for CPU $cpu" 2
 | 
			
		||||
			if [ -z "$line" ]; then
 | 
			
		||||
				line="\${cpugraph cpu$cpu 36,$width}"
 | 
			
		||||
			else
 | 
			
		||||
				line="$line \${cpugraph cpu$cpu 36,$width}"
 | 
			
		||||
			fi
 | 
			
		||||
	if (( _optgraph > 0 )); then
 | 
			
		||||
		local gpl=1
 | 
			
		||||
		if (( nproc <= 2 )); then
 | 
			
		||||
			gpl=1
 | 
			
		||||
		elif (( nproc <= 4 )); then
 | 
			
		||||
			gpl=2
 | 
			
		||||
		elif (( nproc <= 8 )); then
 | 
			
		||||
			gpl=4
 | 
			
		||||
		else
 | 
			
		||||
			gpl=8
 | 
			
		||||
		fi
 | 
			
		||||
		local width=$(( 400 / gpl ))
 | 
			
		||||
		log "Generating $gpl graphs per row of CPU core stats" 1
 | 
			
		||||
		log "Graphs will be $width wide" 2
 | 
			
		||||
		local cpuinfo
 | 
			
		||||
		for i in $(seq 1 "$gpl" "$nproc"); do
 | 
			
		||||
			# Generate lines
 | 
			
		||||
			local line
 | 
			
		||||
			for j in $(seq 0 $(( gpl - 1 ))); do
 | 
			
		||||
				# Generate graphs
 | 
			
		||||
				local cpu=$(( i + j ))
 | 
			
		||||
				log "Generating graph for CPU $cpu" 2
 | 
			
		||||
				if [ -z "$line" ]; then
 | 
			
		||||
					line="\${cpugraph cpu$cpu 36,$width}"
 | 
			
		||||
				else
 | 
			
		||||
					line="$line \${cpugraph cpu$cpu 36,$width}"
 | 
			
		||||
				fi
 | 
			
		||||
			done
 | 
			
		||||
			# Trim whitespace
 | 
			
		||||
			line="\${color8}${line%" "}\$color"
 | 
			
		||||
			log "Appending line: $line" 2
 | 
			
		||||
			cpuinfo="$cpuinfo$line\n"
 | 
			
		||||
			unset line
 | 
			
		||||
		done
 | 
			
		||||
		# Trim whitespace
 | 
			
		||||
		line="\${color8}${line%" "}\$color"
 | 
			
		||||
		log "Appending line: $line" 2
 | 
			
		||||
		cpuinfo="$cpuinfo$line\n"
 | 
			
		||||
		unset line
 | 
			
		||||
	done
 | 
			
		||||
	while [ "$cpuinfo" != "${cpuinfo%\\n}" ]; do
 | 
			
		||||
		cpuinfo="${cpuinfo%\\n}"
 | 
			
		||||
	done
 | 
			
		||||
	echo -e "$cpuinfo" >> "$_optout"
 | 
			
		||||
	for i in $(seq $topitems); do
 | 
			
		||||
		while [ "$cpuinfo" != "${cpuinfo%\\n}" ]; do
 | 
			
		||||
			cpuinfo="${cpuinfo%\\n}"
 | 
			
		||||
		done
 | 
			
		||||
		echo -e "$cpuinfo" >> "$_optout"
 | 
			
		||||
	fi
 | 
			
		||||
	for i in $(seq $_opttopitems); do
 | 
			
		||||
		echo "\${color8}\${top name $i}\$color\$alignr\${top cpu $i}%" >> "$_optout"
 | 
			
		||||
	done
 | 
			
		||||
 | 
			
		||||
@@ -211,13 +218,17 @@ step_text() {
 | 
			
		||||
	cat <<- 'EOF' >> "$_optout"
 | 
			
		||||
	${color3}$hr$color
 | 
			
		||||
	${font Roboto:style=Medium:size=9}Memory$font: $mem / $memmax used$alignr$memperc%
 | 
			
		||||
	${color9}${memgraph}$color
 | 
			
		||||
	Memory$alignr$memeasyfree ${color9}${membar}$color
 | 
			
		||||
	EOF
 | 
			
		||||
	if [ -n "$(swapon)" ]; then
 | 
			
		||||
		echo "Swap\$alignr\$swapfree \${color9}\${swapbar}\$color" >> "$_optout"
 | 
			
		||||
	if (( _optgraph > 0 )); then
 | 
			
		||||
		echo -e '${color9}${memgraph}$color' >> "$_optout"
 | 
			
		||||
	fi
 | 
			
		||||
	for i in $(seq $topitems); do
 | 
			
		||||
	if (( _optbar > 0 )); then
 | 
			
		||||
		echo -e 'Memory$alignr$memeasyfree ${color9}${membar}$color' >> "$_optout"
 | 
			
		||||
		if [ -n "$(swapon)" ]; then
 | 
			
		||||
			echo "Swap\$alignr\$swapfree \${color9}\${swapbar}\$color" >> "$_optout"
 | 
			
		||||
		fi
 | 
			
		||||
	fi
 | 
			
		||||
	for i in $(seq $_opttopitems); do
 | 
			
		||||
		echo "\${color9}\${top_mem name $i}\$color\$alignr\${top_mem mem $i}%" >> "$_optout"
 | 
			
		||||
	done
 | 
			
		||||
 | 
			
		||||
@@ -225,15 +236,19 @@ step_text() {
 | 
			
		||||
	cat <<- 'EOF' >> "$_optout"
 | 
			
		||||
	${color3}$hr$color
 | 
			
		||||
	${font Roboto:style=Medium:size=9}Disk$font (R/W):$alignr${diskio /dev/sda}
 | 
			
		||||
	${color7}${diskiograph_read /dev/sda 36,200} ${diskiograph_write /dev/sda 36,200}$color
 | 
			
		||||
	EOF
 | 
			
		||||
	if (( _optgraph > 0 )); then
 | 
			
		||||
		echo '${color7}${diskiograph_read /dev/sda 36,200} ${diskiograph_write /dev/sda 36,200}$color' >> "$_optout"
 | 
			
		||||
	fi
 | 
			
		||||
	# Mountpoint detection
 | 
			
		||||
	for mountpoint in / /home /var /usr /opt /boot /boot/efi; do
 | 
			
		||||
		if mountpoint $mountpoint > /dev/null 2>&1; then
 | 
			
		||||
			echo "$mountpoint\$alignr\${fs_free $mountpoint} \${color7}\${fs_bar $mountpoint}\$color" >> "$_optout"
 | 
			
		||||
		fi
 | 
			
		||||
	done
 | 
			
		||||
	for i in $(seq $topitems); do
 | 
			
		||||
	if (( _optbar > 0 )); then
 | 
			
		||||
		for mountpoint in / /home /var /usr /opt /boot /boot/efi; do
 | 
			
		||||
			if mountpoint $mountpoint > /dev/null 2>&1; then
 | 
			
		||||
				echo "$mountpoint\$alignr\${fs_free $mountpoint} \${color7}\${fs_bar $mountpoint}\$color" >> "$_optout"
 | 
			
		||||
			fi
 | 
			
		||||
		done
 | 
			
		||||
	fi
 | 
			
		||||
	for i in $(seq $_opttopitems); do
 | 
			
		||||
		echo "\${color7}\${top_io name $i}\$color\$alignr\${top_io io_perc $i}%" >> "$_optout"
 | 
			
		||||
	done
 | 
			
		||||
 | 
			
		||||
@@ -243,10 +258,10 @@ step_text() {
 | 
			
		||||
	${font Roboto:style=Medium:size=9}Network$font:${alignr}Default $gw_iface${if_up wlp1s0}
 | 
			
		||||
	EOF
 | 
			
		||||
	for interface in $(iw dev | awk '$1=="Interface"{print $2}'); do
 | 
			
		||||
		cat <<- EOF >>"$_optout"
 | 
			
		||||
		$interface (U/D): \$alignr\${addr $interface} / \${wireless_essid $interface}
 | 
			
		||||
		\${color6}\${upspeedgraph $interface 36,200} \${downspeedgraph $interface 36,200}\$color
 | 
			
		||||
		EOF
 | 
			
		||||
		echo "$interface (U/D): \$alignr\${addr $interface} / \${wireless_essid $interface}" >> "$_optout"
 | 
			
		||||
		if (( _optgraph > 0 )); then
 | 
			
		||||
			echo "\${color6}\${upspeedgraph $interface 36,200} \${downspeedgraph $interface 36,200}\$color" >> "$_optout"
 | 
			
		||||
		fi
 | 
			
		||||
	done
 | 
			
		||||
	echo "]]" >> "$_optout"
 | 
			
		||||
}
 | 
			
		||||
@@ -262,14 +277,23 @@ main() {
 | 
			
		||||
	# Parse out arguments
 | 
			
		||||
	while [ -n "$1" ]; do
 | 
			
		||||
		# Parse out flags
 | 
			
		||||
		while getopts ":ho:v" opt; do
 | 
			
		||||
		while getopts ":bgho:t:v" opt; do
 | 
			
		||||
			case $opt in
 | 
			
		||||
				b)
 | 
			
		||||
					_optbar=0
 | 
			
		||||
					;;
 | 
			
		||||
				g)
 | 
			
		||||
					_optgraph=0
 | 
			
		||||
					;;
 | 
			
		||||
				o)
 | 
			
		||||
					_optout="$OPTARG"
 | 
			
		||||
					;;
 | 
			
		||||
				h)
 | 
			
		||||
					_opthelp=1
 | 
			
		||||
					;;
 | 
			
		||||
				t)
 | 
			
		||||
					_opttopitems="$OPTARG"
 | 
			
		||||
					;;
 | 
			
		||||
				v)
 | 
			
		||||
					_optverbose+=1
 | 
			
		||||
					;;
 | 
			
		||||
@@ -292,7 +316,9 @@ main() {
 | 
			
		||||
	# Early hook for help
 | 
			
		||||
	[ -n "$_opthelp" ] && printhelp && exit 0
 | 
			
		||||
	# Validate critical options
 | 
			
		||||
	# TODO: That
 | 
			
		||||
	if ! (( _opttopitems >= 0 )); then
 | 
			
		||||
		error "Option -t requires non-negative integer as argument" 2
 | 
			
		||||
	fi
 | 
			
		||||
	# Validate core program dependencies
 | 
			
		||||
	log "Validating dependencies" 2
 | 
			
		||||
	if ! has awk basename iw seq; then
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user