fixed load avarage and uptime not showing, fixed unquoted variables

pull/52/head
aristocratos 2020-04-27 21:11:51 +02:00
parent b4d2badf6b
commit f22be9cf16
2 changed files with 35 additions and 29 deletions

View File

@ -13,7 +13,7 @@
* [Compability](#compability) * [Compability](#compability)
* [Dependencies](#dependencies) * [Dependencies](#dependencies)
* [Screenshots](#screenshots) * [Screenshots](#screenshots)
* [Installation](#installation) * [Installation](#installation) (Updated)
* [Configurability](#configurability) * [Configurability](#configurability)
* [TODO](#todo) (Updated) * [TODO](#todo) (Updated)
* [License](#license) * [License](#license)
@ -92,25 +92,31 @@ Options menu.
## Installation ## Installation
#### Manual installation
Copy or link "bashtop" into PATH, or just run from cloned directory... Copy or link "bashtop" into PATH, or just run from cloned directory...
Also available in the Arch Linux repository as [bashtop](https://www.archlinux.org/packages/community/any/bashtop/) #### Arch based
Available in the Arch Linux repository as [bashtop](https://www.archlinux.org/packages/community/any/bashtop/)
Also available in the AUR as [bashtop-git](https://aur.archlinux.org/packages/bashtop-git/) Also available in the AUR as [bashtop-git](https://aur.archlinux.org/packages/bashtop-git/)
Also available for debian/ubuntu from [Azlux's repository](http://packages.azlux.fr/) #### Debian based
Or use quick installation Available for debian/ubuntu from [Azlux's repository](http://packages.azlux.fr/)
>quick install go to DEB folder and type
``` Or use quick installation:
>Quick install go to DEB folder and type
``` bash
sudo ./build sudo ./build
``` ```
>to uninstall it go to DEB folder and type >to uninstall it go to DEB folder and type
``` ``` bash
sudo ./build --remove sudo ./build --remove
``` ```

40
bashtop
View File

@ -194,7 +194,7 @@ init_() { #? Collect needed information and set options before startig main loop
local param_var local param_var
if [[ -e /usr/include/asm-generic/param.h ]]; then if [[ -e /usr/include/asm-generic/param.h ]]; then
param_var="$(</usr/include/asm-generic/param.h)" param_var="$(</usr/include/asm-generic/param.h)"
get_value -v cpu[hz] -sv "param_var" -k "define HZ" -i get_value -v 'cpu[hz]' -sv "param_var" -k "define HZ" -i
else else
cpu[hz]="100" cpu[hz]="100"
fi fi
@ -212,7 +212,7 @@ init_() { #? Collect needed information and set options before startig main loop
collect_mem init collect_mem init
#* Get default network device from "ip route" command and call init for net collection #* Get default network device from "ip route" command and call init for net collection
get_value -v net[device] -ss "$(ip route get 1.1.1.1)" -k "dev" -mk 1 get_value -v 'net[device]' -ss "$(ip route get 1.1.1.1)" -k "dev" -mk 1
collect_net init collect_net init
#* Check if newer version of bashtop is available from https://github.com/aristocratos/bashtop #* Check if newer version of bashtop is available from https://github.com/aristocratos/bashtop
@ -662,12 +662,12 @@ get_cpu_info() {
local lscpu_var param_var local lscpu_var param_var
lscpu_var="$(lscpu)" lscpu_var="$(lscpu)"
if [[ -z ${cpu[threads]} || -z ${cpu[cores]} ]]; then if [[ -z ${cpu[threads]} || -z ${cpu[cores]} ]]; then
get_value -v cpu[threads] -sv "lscpu_var" -k "CPU(s):" -i get_value -v 'cpu[threads]' -sv "lscpu_var" -k "CPU(s):" -i
get_value -v cpu[cores] -sv "lscpu_var" -k "Core(s)" -i get_value -v 'cpu[cores]' -sv "lscpu_var" -k "Core(s)" -i
fi fi
if [[ -z $custom_cpu_name ]]; then if [[ -z $custom_cpu_name ]]; then
if ! get_value -v cpu[model] -sv "lscpu_var" -k "Model name:" -a -b -k "CPU" -mk -1; then if ! get_value -v 'cpu[model]' -sv "lscpu_var" -k "Model name:" -a -b -k "CPU" -mk -1; then
get_value -v cpu[model] -sv "lscpu_var" -k "Model name:" -r " " get_value -v 'cpu[model]' -sv "lscpu_var" -k "Model name:" -r " "
fi fi
else else
cpu[model]="${custom_cpu_name}" cpu[model]="${custom_cpu_name}"
@ -1184,7 +1184,7 @@ create_mini_graph() { #? Create a one line high graph from an array of percenta
#* Round current input_array value divided by 10 to closest whole number #* Round current input_array value divided by 10 to closest whole number
org_value=${input_array[offset+x]} org_value=${input_array[offset+x]}
if ((org_value<0)); then org_value=0; fi if ((org_value<0)); then org_value=0; fi
if ((org_value==100)); then cur_value=10 if ((org_value>=100)); then cur_value=10
elif [[ ${#org_value} -gt 1 && ${org_value:(-1)} -ge 5 ]]; then cur_value=$((${org_value::1}+1)) elif [[ ${#org_value} -gt 1 && ${org_value:(-1)} -ge 5 ]]; then cur_value=$((${org_value::1}+1))
elif [[ ${#org_value} -gt 1 && ${org_value:(-1)} -lt 5 ]]; then cur_value=$((${org_value::1})) elif [[ ${#org_value} -gt 1 && ${org_value:(-1)} -lt 5 ]]; then cur_value=$((${org_value::1}))
elif [[ ${org_value:(-1)} -ge 5 ]]; then cur_value=1 elif [[ ${org_value:(-1)} -ge 5 ]]; then cur_value=1
@ -1356,14 +1356,14 @@ collect_cpu() { #? Collects cpu stats from /proc/stat and compares with previous
done done
#* Get current cpu frequency from "/proc/cpuinfo" and convert to appropriate unit #* 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 if [[ -z ${cpu[no_cpu_info]} ]] && ! get_value -v 'cpu[freq]' -sf "/proc/cpuinfo" -k "cpu MHz" -i; then
cpu[no_cpu_info]=1 cpu[no_cpu_info]=1
fi fi
#* If getting cpu frequency from "proc/cpuinfo" was unsuccessfull try "/sys/devices/../../scaling_cur_freq" #* If getting cpu frequency from "proc/cpuinfo" was unsuccessfull try "/sys/devices/../../scaling_cur_freq"
if [[ -n ${cpu[no_cpu_info]} && -e "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq" ]]; then if [[ -n ${cpu[no_cpu_info]} && -e "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq" ]]; then
get_value -v cpu[freq] -sf "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq" -i get_value -v 'cpu[freq]' -sf "/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq" -i
printf -v cpu[freq] "%.0f0" "${cpu[freq]}e-4" printf -v 'cpu[freq]' "%.0f0" "${cpu[freq]}e-4"
fi fi
if ((${#cpu[freq]}>3)); then cpu[freq_string]="${cpu[freq]::-3}.${cpu[freq]:(-3):1} GHz" if ((${#cpu[freq]}>3)); then cpu[freq_string]="${cpu[freq]::-3}.${cpu[freq]:(-3):1} GHz"
@ -1389,13 +1389,13 @@ collect_cpu_temps() { #? Collect cpu temperatures
sens_var="$(sensors)" sens_var="$(sensors)"
#* Get CPU package temp #* Get CPU package temp
if get_value -v cpu[temp_0] -sv "sens_var" -k "Package*:" -mk 1; then if get_value -v 'cpu[temp_0]' -sv "sens_var" -k "Package*:" -mk 1; then
#* If successful get temperature unit, convert temp to integer and get high, crit and core temps #* If successful get temperature unit, convert temp to integer and get high, crit and core temps
cpu[temp_unit]=${cpu[temp_0]:(-2)}; cpu[temp_0]=${cpu[temp_0]%.*}; if [[ ${cpu[temp_0]::1} == "+" ]]; then cpu[temp_0]=${cpu[temp_0]#+}; fi cpu[temp_unit]=${cpu[temp_0]:(-2)}; cpu[temp_0]=${cpu[temp_0]%.*}; if [[ ${cpu[temp_0]::1} == "+" ]]; then cpu[temp_0]=${cpu[temp_0]#+}; fi
if [[ -z ${cpu[temp_high]} ]]; then if [[ -z ${cpu[temp_high]} ]]; then
get_value -v "cpu[temp_high]" -sv "sens_var" -k "Package*high =" -m 2 -r "[^0-9.]" -b -i get_value -v 'cpu[temp_high]' -sv "sens_var" -k "Package*high =" -m 2 -r "[^0-9.]" -b -i
get_value -v "cpu[temp_crit]" -sv "sens_var" -k "Package*crit =" -m 2 -r "[^0-9.]" -b -i get_value -v 'cpu[temp_crit]' -sv "sens_var" -k "Package*crit =" -m 2 -r "[^0-9.]" -b -i
fi fi
for((i=0,it=1;i<threads;i++,it++)); do for((i=0,it=1;i<threads;i++,it++)); do
if ! get_value -v "cpu[temp_${it}]" -sv "sens_var" -k "Core ${i}:" -mk 1 -r "[^0-9.-]" -b -i; then break; fi if ! get_value -v "cpu[temp_${it}]" -sv "sens_var" -k "Core ${i}:" -mk 1 -r "[^0-9.-]" -b -i; then break; fi
@ -1433,21 +1433,21 @@ collect_mem() { #? Collect memory information from "/proc/meminfo"
#* Get memory and swap information from "/proc/meminfo" and calculate percentages #* Get memory and swap information from "/proc/meminfo" and calculate percentages
mem_info="$(</proc/meminfo)" mem_info="$(</proc/meminfo)"
get_value -v mem[total] -sv "mem_info" -k "MemTotal:" -i get_value -v 'mem[total]' -sv "mem_info" -k "MemTotal:" -i
get_value -v mem[available] -sv "mem_info" -k "MemAvailable:" -i get_value -v 'mem[available]' -sv "mem_info" -k "MemAvailable:" -i
mem[available_percent]=$((mem[available]*100/mem[total])) mem[available_percent]=$((mem[available]*100/mem[total]))
mem[used]=$((mem[total]-mem[available])) mem[used]=$((mem[total]-mem[available]))
mem[used_percent]=$((mem[used]*100/mem[total])) mem[used_percent]=$((mem[used]*100/mem[total]))
get_value -v mem[free] -sv "mem_info" -k "MemFree:" -i get_value -v 'mem[free]' -sv "mem_info" -k "MemFree:" -i
mem[free_percent]=$((mem[free]*100/mem[total])) mem[free_percent]=$((mem[free]*100/mem[total]))
get_value -v mem[cached] -sv "mem_info" -k "Cached:" -i get_value -v 'mem[cached]' -sv "mem_info" -k "Cached:" -i
mem[cached_percent]=$((mem[cached]*100/mem[total])) mem[cached_percent]=$((mem[cached]*100/mem[total]))
if [[ -n $swap_on ]] && get_value -v swap[total] -sv "mem_info" -k "SwapTotal:" -i && ((swap[total]>0)); then if [[ -n $swap_on ]] && get_value -v swap[total] -sv "mem_info" -k "SwapTotal:" -i && ((swap[total]>0)); then
get_value -v swap[free] -sv "mem_info" -k "SwapFree:" -i get_value -v 'swap[free]' -sv "mem_info" -k "SwapFree:" -i
swap[free_percent]=$((swap[free]*100/swap[total])) swap[free_percent]=$((swap[free]*100/swap[total]))
swap[used]=$((swap[total]-swap[free])) swap[used]=$((swap[total]-swap[free]))
@ -2054,15 +2054,15 @@ draw_cpu() { #? Draw cpu and core graphs and print percentages
done done
#* Print load average and uptime #* Print load average and uptime
if ((pt_line+y+1<=p_height)); then if ((pt_line+y+3<p_line+p_height)); then
local avg_string avg_width local avg_string avg_width
if [[ $check_temp == true ]]; then avg_string="Load Average: "; avg_width=7; else avg_string="L AVG: "; avg_width=5; fi if [[ $check_temp == true ]]; then avg_string="Load Average: "; avg_width=7; else avg_string="L AVG: "; avg_width=5; fi
print -v cpu_out_var -m $((pt_line+y+1)) $pt_col -fg ${theme[main_fg]} -t "${avg_string}" print -v cpu_out_var -m $((pt_line+y+1)) $pt_col -fg ${theme[main_fg]} -t "${avg_string}"
for avg_string in ${cpu[load_avg]}; do for avg_string in ${cpu[load_avg]}; do
print -v cpu_out_var -jc $avg_width -t "${avg_string::4}" print -v cpu_out_var -jc $avg_width -t "${avg_string::4}"
done done
print -v cpu_out_var -m $((line+height-1)) $((col+1)) -fg ${theme[inactive_fg]} -trans -t "up ${cpu[uptime]}"
fi fi
print -v cpu_out_var -m $((line+height-1)) $((col+1)) -fg ${theme[inactive_fg]} -trans -t "up ${cpu[uptime]}"
#* Print current CPU frequency right of the title in the meter box #* Print current CPU frequency right of the title in the meter box
if [[ -n ${cpu[freq_string]} ]]; then print -v cpu_out_var -m $((p_line-1)) $((p_col+p_width-5-${#cpu[freq_string]})) -fg ${theme[div_line]} -t "┤" -fg ${theme[title]} -b -t "${cpu[freq_string]}" -rs -fg ${theme[div_line]} -t "├"; fi if [[ -n ${cpu[freq_string]} ]]; then print -v cpu_out_var -m $((p_line-1)) $((p_col+p_width-5-${#cpu[freq_string]})) -fg ${theme[div_line]} -t "┤" -fg ${theme[title]} -b -t "${cpu[freq_string]}" -rs -fg ${theme[div_line]} -t "├"; fi