diff --git a/scripts/cpu_info.sh b/scripts/cpu_info.sh index 6fbeb5b..a164cf5 100755 --- a/scripts/cpu_info.sh +++ b/scripts/cpu_info.sh @@ -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 diff --git a/scripts/gpu_usage.sh b/scripts/gpu_usage.sh index 4babdc0..0412145 100755 --- a/scripts/gpu_usage.sh +++ b/scripts/gpu_usage.sh @@ -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 diff --git a/scripts/network_bandwidth.sh b/scripts/network_bandwidth.sh index 71614d0..e0dbc39 100755 --- a/scripts/network_bandwidth.sh +++ b/scripts/network_bandwidth.sh @@ -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 diff --git a/scripts/network_ping.sh b/scripts/network_ping.sh index e4692bc..8d57514 100644 --- a/scripts/network_ping.sh +++ b/scripts/network_ping.sh @@ -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 diff --git a/scripts/ram_info.sh b/scripts/ram_info.sh index 25677e2..1662c63 100755 --- a/scripts/ram_info.sh +++ b/scripts/ram_info.sh @@ -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 diff --git a/scripts/sleep_weather.sh b/scripts/sleep_weather.sh index e8f8d25..13446d7 100755 --- a/scripts/sleep_weather.sh +++ b/scripts/sleep_weather.sh @@ -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 diff --git a/scripts/weather.sh b/scripts/weather.sh index 6debde5..ecf4ca4 100755 --- a/scripts/weather.sh +++ b/scripts/weather.sh @@ -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 '❄ '