From f51d0ebfdc4732ffa296f6865f2b87609d9b8573 Mon Sep 17 00:00:00 2001 From: aristocratos Date: Sun, 26 Apr 2020 14:24:48 +0200 Subject: [PATCH] cleanup and formatting --- bashtop | 43 ++++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 23 deletions(-) diff --git a/bashtop b/bashtop index 9e42cbe..8dfe651 100755 --- a/bashtop +++ b/bashtop @@ -606,7 +606,7 @@ is_int() { #? Check if value(s) is integer is_float() { #? Check if value(s) is floating point local param for param; do - if [[ ! $param =~ ^[\-]?[0-9]*[,|.][0-9]+$ ]]; then return 1; fi + if [[ ! $param =~ ^[\-]?[0-9]*[,.][0-9]+$ ]]; then return 1; fi done } @@ -690,9 +690,9 @@ get_value() { #? Get a value from a file, variable or array by searching for a n -sf|-source-file) input="$(<"$2")"; shift;; #? File as source -sv|-source-var) input="${!2}"; shift;; #? Variable as source -sa|-source-array) local -n tmp_array=$2; input="${tmp_array[*]}"; shift;; #? Array as source - -fp|-floating-point) reg="[\-]?[0-9]*[.|,][0-9]+"; match=1;; #? Match floating point value + -fp|-floating-point) reg="[\-]?[0-9]*[.,][0-9]+"; match=1;; #? Match floating point value -math) math="$2"; shift;; #? Perform math on a integer value, "x" represents value, only works if "integer" argument is given - -i|-integer) reg="[\-]?[0-9]+[.|,]?[0-9]*"; int=1; match=1;; #? Match integer value or float and convert to int + -i|-integer) reg="[\-]?[0-9]+[.,]?[0-9]*"; int=1; match=1;; #? Match integer value or float and convert to int -r|-remove) remove+=("$2"); shift;; #? Format output by removing entered regex, can be used multiple times -v|-variable-out) local -n found="$2"; ext_var=1; shift;; #? Output to variable -map|-map-array) local -n array_out="$2"; ext_var=1; ext_arr=1; shift;; #? Map output to array @@ -791,20 +791,20 @@ cur_pos() { #? Get cursor postion, argument "line" prints current line, argument if [[ -z $1 || $1 == "col" ]]; then echo -n "$col"; fi } -create_box() { #? Draw a box with an optional titlebar and title at given location +create_box() { #? Draw a box with an optional title at given location local width height col line title ltype hpos vpos i hlines vlines color line_color c_rev=0 box_out ext_var fill until (($#==0)); do case $1 in -f|-full) col=1; line=1; width=$((tty_width)); height=$((tty_height));; #? Use full terminal size for box - -c|-col) if is_int "$2"; then col=$2; shift; fi;; #? Column position to start box - -l|-line) if is_int "$2"; then line=$2; shift; fi;; #? Line position to start box - -w|-width) if is_int "$2"; then width=$2; shift; fi;; #? Width of box - -h|-height) if is_int "$2"; then height=$2; shift; fi;; #? Height of box - -t|-title) if [[ -n $2 ]]; then title="$2"; shift; fi;; #? Draw title without titlebar + -c|-col) if is_int "$2"; then col=$2; shift; fi;; #? Column position to start box + -l|-line) if is_int "$2"; then line=$2; shift; fi;; #? Line position to start box + -w|-width) if is_int "$2"; then width=$2; shift; fi;; #? Width of box + -h|-height) if is_int "$2"; then height=$2; shift; fi;; #? Height of box + -t|-title) if [[ -n $2 ]]; then title="$2"; shift; fi;; #? Draw title without titlebar -s|-single) ltype="single";; #? Use single lines -d|-double) ltype="double";; #? Use double lines - -lc|-line-color) line_color="$2"; shift;; #? Color of the lines - -fill) fill=1;; + -lc|-line-color) line_color="$2"; shift;; #? Color of the lines + -fill) fill=1;; #? Fill background of box -v|-variable) local -n box_out=$2; ext_var=1; shift;; #? Output box to a variable esac shift @@ -865,7 +865,7 @@ create_meter() { #? Create a horizontal percentage meter, usage; create_meter < #* Argument parsing until (($#==0)); do case $1 in - -p|-place) if is_int "${@:2:2}"; then line=$2; col=$3; shift 2; fi;; #? Placement for meter + -p|-place) if is_int "${@:2:2}"; then line=$2; col=$3; shift 2; fi;; #? Placement for meter -w|-width) width=$2; shift;; #? Width of meter in columns -c|-color) local -n colors=$2; shift;; #? Name of an array containing colors from index 0-100 -i|-invert) invert=1;; #? Invert meter @@ -1329,12 +1329,14 @@ collect_cpu() { #? Collects cpu stats from /proc/stat and compares with previous #* Get values from /proc/stat, compare to get cpu usage thread=0 while ((thread20)); then @@ -1355,7 +1355,6 @@ collect_cpu() { #? Collects cpu stats from /proc/stat and compares with previous fi done - #* Get current cpu frequency from "/proc/cpuinfo" and convert to appropriate unit if [[ -z ${cpu[no_cpu_info]} ]] && ! get_value -v cpu[freq] -sf "/proc/cpuinfo" -k "cpu MHz" -i; then cpu[no_cpu_info]=1 @@ -3433,8 +3432,6 @@ main_loop() { #? main loop... done - - #* If time left is too low to process any input more than twice in succession, add 100ms to update timer elif ((++late_update==5)); then update_ms=$((update_ms+100))