mirror of
https://github.com/TECHNOFAB11/tmux2k.git
synced 2025-12-11 23:50:08 +01:00
Fix potential errors in scripts
This commit is contained in:
parent
8c7f582b53
commit
c1493ce604
7 changed files with 31 additions and 31 deletions
|
|
@ -3,14 +3,14 @@
|
||||||
export LC_ALL=en_US.UTF-8
|
export LC_ALL=en_US.UTF-8
|
||||||
|
|
||||||
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
source $current_dir/utils.sh
|
source "$current_dir"/utils.sh
|
||||||
|
|
||||||
get_percent()
|
get_percent()
|
||||||
{
|
{
|
||||||
case $(uname -s) in
|
case $(uname -s) in
|
||||||
Linux)
|
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"%"}')
|
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)
|
Darwin)
|
||||||
|
|
@ -51,7 +51,7 @@ main() {
|
||||||
cpu_percent=$(get_percent)
|
cpu_percent=$(get_percent)
|
||||||
echo "$cpu_label $cpu_percent"
|
echo "$cpu_label $cpu_percent"
|
||||||
fi
|
fi
|
||||||
sleep $RATE
|
sleep "$RATE"
|
||||||
}
|
}
|
||||||
|
|
||||||
# run main driver
|
# run main driver
|
||||||
|
|
|
||||||
|
|
@ -3,14 +3,14 @@
|
||||||
export LC_ALL=en_US.UTF-8
|
export LC_ALL=en_US.UTF-8
|
||||||
|
|
||||||
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||||
source $current_dir/utils.sh
|
source "$current_dir"/utils.sh
|
||||||
|
|
||||||
get_platform()
|
get_platform()
|
||||||
{
|
{
|
||||||
case $(uname -s) in
|
case $(uname -s) in
|
||||||
Linux)
|
Linux)
|
||||||
gpu=$(lspci -v | grep VGA | head -n 1 | awk '{print $5}')
|
gpu=$(lspci -v | grep VGA | head -n 1 | awk '{print $5}')
|
||||||
echo $gpu
|
echo "$gpu"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
Darwin)
|
Darwin)
|
||||||
|
|
@ -41,7 +41,7 @@ main()
|
||||||
gpu_label=$(get_tmux_option "@tmux2k-gpu-usage-label" "GPU")
|
gpu_label=$(get_tmux_option "@tmux2k-gpu-usage-label" "GPU")
|
||||||
gpu_usage=$(get_gpu)
|
gpu_usage=$(get_gpu)
|
||||||
echo "$gpu_label $gpu_usage"
|
echo "$gpu_label $gpu_usage"
|
||||||
sleep $RATE
|
sleep "$RATE"
|
||||||
}
|
}
|
||||||
|
|
||||||
# run the main driver
|
# run the main driver
|
||||||
|
|
|
||||||
|
|
@ -12,21 +12,21 @@ main() {
|
||||||
output_download_unit=""
|
output_download_unit=""
|
||||||
output_upload_unit=""
|
output_upload_unit=""
|
||||||
|
|
||||||
initial_download=$(cat /sys/class/net/$network_name/statistics/rx_bytes)
|
initial_download=$(cat /sys/class/net/"$network_name"/statistics/rx_bytes)
|
||||||
initial_upload=$(cat /sys/class/net/$network_name/statistics/tx_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_download=$(cat /sys/class/net/"$network_name"/statistics/rx_bytes)
|
||||||
final_upload=$(cat /sys/class/net/$network_name/statistics/tx_bytes)
|
final_upload=$(cat /sys/class/net/"$network_name"/statistics/tx_bytes)
|
||||||
|
|
||||||
total_download_bps=$(expr $final_download - $initial_download)
|
total_download_bps=$(expr "$final_download" - "$initial_download")
|
||||||
total_upload_bps=$(expr $final_upload - $initial_upload)
|
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=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2 * $2)}')
|
||||||
output_download_unit="gB/s"
|
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=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2)}')
|
||||||
output_download_unit="mB/s"
|
output_download_unit="mB/s"
|
||||||
else
|
else
|
||||||
|
|
@ -34,10 +34,10 @@ main() {
|
||||||
output_download_unit="kB/s"
|
output_download_unit="kB/s"
|
||||||
fi
|
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=$(echo "$total_download_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2 * $2)}')
|
||||||
output_upload_unit="gB/s"
|
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=$(echo "$total_upload_bps 1024" | awk '{printf "%.2f \n", $1/($2 * $2)}')
|
||||||
output_upload_unit="mB/s"
|
output_upload_unit="mB/s"
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ export LC_ALL=en_US.UTF-8
|
||||||
# @tmux2k-ping-rate 5
|
# @tmux2k-ping-rate 5
|
||||||
|
|
||||||
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
current_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
source $current_dir/utils.sh
|
source "$current_dir"/utils.sh
|
||||||
|
|
||||||
ping_function() {
|
ping_function() {
|
||||||
case $(uname -s) in
|
case $(uname -s) in
|
||||||
|
|
@ -26,9 +26,9 @@ ping_function() {
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
|
||||||
echo $(ping_function)
|
echo "$(ping_function)"
|
||||||
RATE=$(get_tmux_option "@tmux2k-ping-rate" 5)
|
RATE=$(get_tmux_option "@tmux2k-ping-rate" 5)
|
||||||
sleep $RATE
|
sleep "$RATE"
|
||||||
}
|
}
|
||||||
|
|
||||||
# run main driver
|
# run main driver
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,11 @@ get_percent()
|
||||||
total_mem_gb=$(free -g | awk '/^Mem/ {print $2}')
|
total_mem_gb=$(free -g | awk '/^Mem/ {print $2}')
|
||||||
used_mem=$(free -g | awk '/^Mem/ {print $3}')
|
used_mem=$(free -g | awk '/^Mem/ {print $3}')
|
||||||
total_mem=$(free -h | awk '/^Mem/ {print $2}')
|
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}')
|
memory_usage=$(free -m | awk '/^Mem/ {print $3}')
|
||||||
total_mem_mb=$(free -m | awk '/^Mem/ {print $2}')
|
total_mem_mb=$(free -m | awk '/^Mem/ {print $2}')
|
||||||
echo $memory_usage\M\B/$total_mem_mb\M\B
|
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}')
|
memory_usage=$(free -m | awk '/^Mem/ {print $3}')
|
||||||
echo $memory_usage\M\B/$total_mem_gb\G\B
|
echo $memory_usage\M\B/$total_mem_gb\G\B
|
||||||
else
|
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
|
# 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}')
|
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}')
|
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
|
echo $used_mem\M\B/$total_mem
|
||||||
else
|
else
|
||||||
memory=$(($used_mem/1024))
|
memory=$(($used_mem/1024))
|
||||||
|
|
@ -48,7 +48,7 @@ get_percent()
|
||||||
total_mem=$(($(sysctl -n hw.physmem) / 1024 / 1024))
|
total_mem=$(($(sysctl -n hw.physmem) / 1024 / 1024))
|
||||||
used_mem=$((total_mem - free_mem))
|
used_mem=$((total_mem - free_mem))
|
||||||
echo $used_mem
|
echo $used_mem
|
||||||
if (( $used_mem < 1024 )); then
|
if (( "$used_mem" < 1024 )); then
|
||||||
echo $used_mem\M\B/$total_mem
|
echo $used_mem\M\B/$total_mem
|
||||||
else
|
else
|
||||||
memory=$(($used_mem/1024))
|
memory=$(($used_mem/1024))
|
||||||
|
|
@ -69,7 +69,7 @@ main()
|
||||||
ram_label=$(get_tmux_option "@tmux2k-ram-usage-label" "")
|
ram_label=$(get_tmux_option "@tmux2k-ram-usage-label" "")
|
||||||
ram_percent=$(get_percent)
|
ram_percent=$(get_percent)
|
||||||
echo "$ram_label $ram_percent"
|
echo "$ram_label $ram_percent"
|
||||||
sleep $RATE
|
sleep "$RATE"
|
||||||
}
|
}
|
||||||
|
|
||||||
#run main driver
|
#run main driver
|
||||||
|
|
|
||||||
|
|
@ -28,11 +28,11 @@ main()
|
||||||
printf "Loading..." > $DATAFILE
|
printf "Loading..." > $DATAFILE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$current_dir/weather.sh > $DATAFILE
|
"$current_dir"/weather.sh > $DATAFILE
|
||||||
|
|
||||||
while tmux has-session &> /dev/null
|
while tmux has-session &> /dev/null
|
||||||
do
|
do
|
||||||
$current_dir/weather.sh $fahrenheit $location $fixedlocation > $DATAFILE
|
"$current_dir"/weather.sh "$fahrenheit" "$location" "$fixedlocation" > $DATAFILE
|
||||||
if tmux has-session &> /dev/null
|
if tmux has-session &> /dev/null
|
||||||
then
|
then
|
||||||
sleep 1200
|
sleep 1200
|
||||||
|
|
|
||||||
|
|
@ -36,16 +36,16 @@ display_weather()
|
||||||
fi
|
fi
|
||||||
weather_information=$(fetch_weather_information $display_weather)
|
weather_information=$(fetch_weather_information $display_weather)
|
||||||
|
|
||||||
weather_condition=$(echo $weather_information | rev | cut -d ' ' -f2- | rev) # Sunny, Snow, etc
|
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
|
temperature=$(echo "$weather_information" | rev | cut -d ' ' -f 1 | rev) # +31°C, -3°F, etc
|
||||||
unicode=$(forecast_unicode $weather_condition)
|
unicode=$(forecast_unicode "$weather_condition")
|
||||||
|
|
||||||
echo "$unicode${temperature/+/}" # remove the plus sign to the temperature
|
echo "$unicode${temperature/+/}" # remove the plus sign to the temperature
|
||||||
}
|
}
|
||||||
|
|
||||||
forecast_unicode()
|
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
|
if [[ $weather_condition =~ 'snow' ]]; then
|
||||||
echo '❄ '
|
echo '❄ '
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue