Conky: Add a bunch of switches to gen.sh

That I'll never use
This commit is contained in:
Salt 2020-06-12 05:47:03 -05:00
parent 50c087380a
commit cb2d497544

View File

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