Fix potential errors in scripts

This commit is contained in:
Abhishek Keshri 2022-08-13 17:11:48 +05:30
parent 8c7f582b53
commit c1493ce604
No known key found for this signature in database
GPG key ID: 87ABE188E6B98D1C
7 changed files with 31 additions and 31 deletions

View file

@ -3,14 +3,14 @@
export LC_ALL=en_US.UTF-8
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $current_dir/utils.sh
source "$current_dir"/utils.sh
get_percent()
{
case $(uname -s) in
Linux)
percent=$(LC_NUMERIC=en_US.UTF-8 top -bn2 -d 0.01 | grep "Cpu(s)" | tail -1 | sed "s/.*, *\([0-9.]*\)%* id.*/\1/" | awk '{print 100 - $1"%"}')
normalize_percent_len $percent
normalize_percent_len "$percent"
;;
Darwin)
@ -51,7 +51,7 @@ main() {
cpu_percent=$(get_percent)
echo "$cpu_label $cpu_percent"
fi
sleep $RATE
sleep "$RATE"
}
# run main driver

View file

@ -3,14 +3,14 @@
export LC_ALL=en_US.UTF-8
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source $current_dir/utils.sh
source "$current_dir"/utils.sh
get_platform()
{
case $(uname -s) in
Linux)
gpu=$(lspci -v | grep VGA | head -n 1 | awk '{print $5}')
echo $gpu
echo "$gpu"
;;
Darwin)
@ -41,7 +41,7 @@ main()
gpu_label=$(get_tmux_option "@tmux2k-gpu-usage-label" "GPU")
gpu_usage=$(get_gpu)
echo "$gpu_label $gpu_usage"
sleep $RATE
sleep "$RATE"
}
# run the main driver

View file

@ -12,21 +12,21 @@ main() {
output_download_unit=""
output_upload_unit=""
initial_download=$(cat /sys/class/net/$network_name/statistics/rx_bytes)
initial_upload=$(cat /sys/class/net/$network_name/statistics/tx_bytes)
initial_download=$(cat /sys/class/net/"$network_name"/statistics/rx_bytes)
initial_upload=$(cat /sys/class/net/"$network_name"/statistics/tx_bytes)
sleep $INTERVAL
sleep "$INTERVAL"
final_download=$(cat /sys/class/net/$network_name/statistics/rx_bytes)
final_upload=$(cat /sys/class/net/$network_name/statistics/tx_bytes)
final_download=$(cat /sys/class/net/"$network_name"/statistics/rx_bytes)
final_upload=$(cat /sys/class/net/"$network_name"/statistics/tx_bytes)
total_download_bps=$(expr $final_download - $initial_download)
total_upload_bps=$(expr $final_upload - $initial_upload)
total_download_bps=$(expr "$final_download" - "$initial_download")
total_upload_bps=$(expr "$final_upload" - "$initial_upload")
if [ $total_download_bps -gt 1073741824 ]; then
if [ "$total_download_bps" -gt 1073741824 ]; then
output_download=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2 * $2)}')
output_download_unit="gB/s"
elif [ $total_download_bps -gt 1048576 ]; then
elif [ "$total_download_bps" -gt 1048576 ]; then
output_download=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2)}')
output_download_unit="mB/s"
else
@ -34,10 +34,10 @@ main() {
output_download_unit="kB/s"
fi
if [ $total_upload_bps -gt 1073741824 ]; then
if [ "$total_upload_bps" -gt 1073741824 ]; then
output_upload=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2 * $2)}')
output_upload_unit="gB/s"
elif [ $total_upload_bps -gt 1048576 ]; then
elif [ "$total_upload_bps" -gt 1048576 ]; then
output_upload=$(echo "$total_upload_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2)}')
output_upload_unit="mB/s"
else

View file

@ -7,7 +7,7 @@ export LC_ALL=en_US.UTF-8
# @tmux2k-ping-rate 5
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source $current_dir/utils.sh
source "$current_dir"/utils.sh
ping_function() {
case $(uname -s) in
@ -26,9 +26,9 @@ ping_function() {
main() {
echo $(ping_function)
echo "$(ping_function)"
RATE=$(get_tmux_option "@tmux2k-ping-rate" 5)
sleep $RATE
sleep "$RATE"
}
# run main driver

View file

@ -12,11 +12,11 @@ get_percent()
total_mem_gb=$(free -g | awk '/^Mem/ {print $2}')
used_mem=$(free -g | awk '/^Mem/ {print $3}')
total_mem=$(free -h | awk '/^Mem/ {print $2}')
if (( $total_mem_gb == 0)); then
if (( "$total_mem_gb" == 0)); then
memory_usage=$(free -m | awk '/^Mem/ {print $3}')
total_mem_mb=$(free -m | awk '/^Mem/ {print $2}')
echo $memory_usage\M\B/$total_mem_mb\M\B
elif (( $used_mem == 0 )); then
elif (( "$used_mem" == 0 )); then
memory_usage=$(free -m | awk '/^Mem/ {print $3}')
echo $memory_usage\M\B/$total_mem_gb\G\B
else
@ -29,7 +29,7 @@ get_percent()
# Get used memory blocks with vm_stat, multiply by page size to get size in bytes, then convert to MiB
used_mem=$(vm_stat | grep ' active\|wired ' | sed 's/[^0-9]//g' | paste -sd ' ' - | awk -v pagesize=$(pagesize) '{printf "%d\n", ($1+$2) * pagesize / 1048576}')
total_mem=$(system_profiler SPHardwareDataType | grep "Memory:" | awk '{print $2 $3}')
if (( $used_mem < 1024 )); then
if (( "$used_mem" < 1024 )); then
echo $used_mem\M\B/$total_mem
else
memory=$(($used_mem/1024))
@ -48,7 +48,7 @@ get_percent()
total_mem=$(($(sysctl -n hw.physmem) / 1024 / 1024))
used_mem=$((total_mem - free_mem))
echo $used_mem
if (( $used_mem < 1024 )); then
if (( "$used_mem" < 1024 )); then
echo $used_mem\M\B/$total_mem
else
memory=$(($used_mem/1024))
@ -69,7 +69,7 @@ main()
ram_label=$(get_tmux_option "@tmux2k-ram-usage-label" "")
ram_percent=$(get_percent)
echo "$ram_label $ram_percent"
sleep $RATE
sleep "$RATE"
}
#run main driver

View file

@ -28,11 +28,11 @@ main()
printf "Loading..." > $DATAFILE
fi
$current_dir/weather.sh > $DATAFILE
"$current_dir"/weather.sh > $DATAFILE
while tmux has-session &> /dev/null
do
$current_dir/weather.sh $fahrenheit $location $fixedlocation > $DATAFILE
"$current_dir"/weather.sh "$fahrenheit" "$location" "$fixedlocation" > $DATAFILE
if tmux has-session &> /dev/null
then
sleep 1200

View file

@ -36,16 +36,16 @@ display_weather()
fi
weather_information=$(fetch_weather_information $display_weather)
weather_condition=$(echo $weather_information | rev | cut -d ' ' -f2- | rev) # Sunny, Snow, etc
temperature=$(echo $weather_information | rev | cut -d ' ' -f 1 | rev) # +31°C, -3°F, etc
unicode=$(forecast_unicode $weather_condition)
weather_condition=$(echo "$weather_information" | rev | cut -d ' ' -f2- | rev) # Sunny, Snow, etc
temperature=$(echo "$weather_information" | rev | cut -d ' ' -f 1 | rev) # +31°C, -3°F, etc
unicode=$(forecast_unicode "$weather_condition")
echo "$unicode${temperature/+/}" # remove the plus sign to the temperature
}
forecast_unicode()
{
weather_condition=$(echo $weather_condition | awk '{print tolower($0)}')
weather_condition=$(echo "$weather_condition" | awk '{print tolower($0)}')
if [[ $weather_condition =~ 'snow' ]]; then
echo '❄ '