Fix shellcheck warnings

This commit is contained in:
Aaron Kollasch 2023-07-09 00:51:44 -04:00
parent b6fe033952
commit 640eb4c809
No known key found for this signature in database
GPG key ID: F813CAE853E39883

View file

@ -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_cpids_linux() { get_cpids_linux() {
local ppid="$1" local ppid="$1"
local cpids local cpids
cpids="$(pgrep -P "$ppid")"
local cpid local cpid
echo "$ppid" echo "$ppid"
cpids="$(pgrep -P "$ppid")"
for cpid in $cpids; do for cpid in $cpids; do
get_cpids_linux "$cpid" get_cpids_linux "$cpid"
done done
@ -19,9 +19,9 @@ get_cpids_linux() {
get_cpids_unix() { get_cpids_unix() {
local ppid="$1" local ppid="$1"
local cpids local cpids
cpids="$(pgrep -aP "$ppid")"
local cpid local cpid
echo "$ppid" echo "$ppid"
cpids="$(pgrep -aP "$ppid")"
for cpid in $cpids; do for cpid in $cpids; do
get_cpids_unix "$cpid" get_cpids_unix "$cpid"
done done
@ -29,7 +29,7 @@ get_cpids_unix() {
kb_to_mb() { kb_to_mb() {
if [ $# == 0 ]; then if [ $# == 0 ]; then
read num read -r num
else else
num="$1" num="$1"
fi fi
@ -38,7 +38,7 @@ kb_to_mb() {
kb_to_gb() { kb_to_gb() {
if [ $# == 0 ]; then if [ $# == 0 ]; then
read num read -r num
else else
num="$1" num="$1"
fi fi
@ -47,7 +47,7 @@ kb_to_gb() {
round() { round() {
if [ $# == 1 ]; then if [ $# == 1 ]; then
read num read -r num
scale="$1" scale="$1"
elif [ $# == 2 ]; then elif [ $# == 2 ]; then
num="$1" num="$1"
@ -59,9 +59,11 @@ round() {
get_tmux_ram_usage() get_tmux_ram_usage()
{ {
local pid local pid
pid="$(tmux display-message -pF '#{pid}')"
local pids local pids
local total_mem_kb=0 local total_mem_kb=0
local total_mem_mb=0
local total_mem_gb=0
pid="$(tmux display-message -pF '#{pid}')"
case $(uname -s) in case $(uname -s) in
Linux) Linux)
if command -v pstree > /dev/null; then if command -v pstree > /dev/null; then
@ -95,12 +97,12 @@ get_tmux_ram_usage()
# TODO - windows compatability # TODO - windows compatability
;; ;;
esac esac
local total_mem_mb=$(echo "$total_mem_kb" | kb_to_mb | round 0) total_mem_mb=$(kb_to_mb "$total_mem_kb" | round 0)
local total_mem_gb=$(echo "$total_mem_kb" | kb_to_gb | round 0) total_mem_gb=$(kb_to_gb "$total_mem_kb" | round 0)
if (( $total_mem_gb > 0)); then if (( total_mem_gb > 0)); then
echo "${total_mem_gb}GB" echo "${total_mem_gb}GB"
elif (( $total_mem_mb > 0 )); then elif (( total_mem_mb > 0 )); then
echo "${total_mem_mb}MB" echo "${total_mem_mb}MB"
else else
echo "${total_mem_kb}kB" echo "${total_mem_kb}kB"
@ -109,8 +111,6 @@ get_tmux_ram_usage()
main() main()
{ {
# storing the refresh rate in the variable RATE, default is 5
RATE=$(get_tmux_option "@dracula-refresh-rate" 5)
ram_label=$(get_tmux_option "@dracula-tmux-ram-usage-label" "MEM") ram_label=$(get_tmux_option "@dracula-tmux-ram-usage-label" "MEM")
ram_usage=$(get_tmux_ram_usage) ram_usage=$(get_tmux_ram_usage)
echo "$ram_label $ram_usage" echo "$ram_label $ram_usage"