updated waybar

This commit is contained in:
2025-08-28 19:45:40 +02:00
parent bd49925080
commit a1ac6850bb
7 changed files with 167 additions and 35 deletions

45
waybar/scripts/btrfs.sh Executable file
View File

@@ -0,0 +1,45 @@
#!/bin/bash
# Get BTRFS filesystems
btrfs_filesystems=$(df -hT | grep btrfs)
# Initialize variables
total_used=0
total_size=0
# Process each BTRFS filesystem
while read -r line; do
size_str=$(echo "$line" | awk '{print $3}')
used_str=$(echo "$line" | awk '{print $4}')
size=$(echo "$size_str" | sed 's/[GT]//')
used=$(echo "$used_str" | sed 's/[GT]//')
if [[ $size_str == *T ]]; then
size=$(awk -v s="$size" 'BEGIN {print s*1024}')
fi
if [[ $used_str == *T ]]; then
used=$(awk -v u="$used" 'BEGIN {print u*1024}')
fi
total_size=$(awk -v total="$total_size" -v size="$size" 'BEGIN {print total+size}')
total_used=$(awk -v total="$total_used" -v used="$used" 'BEGIN {print total+used}')
done <<< "$btrfs_filesystems"
# Calculate usage percentage
usage_percentage=$(awk -v used="$total_used" -v total="$total_size" 'BEGIN {printf "%.0f", (used/total)*100}')
# Set class based on usage
if [ "$usage_percentage" -gt 95 ]; then
class="max"
elif [ "$usage_percentage" -gt 80 ]; then
class="high"
else
class="normal"
fi
text="$(printf "%.0f" $total_used)G / $(printf "%.0f" $total_size)G"
# Manually construct the JSON output
echo "{\"text\": \"$text\", \"tooltip\": \"\", \"class\": \"$class\"}"

View File

@@ -5,7 +5,7 @@ TEXT="$(printf "%.1f" $(echo "$USAGE"))% $(printf "%.1f" $(echo "scale=2; $TEMP"
CPU=$(lscpu | grep 'Model name' | awk -F': ' '{print $2}' | sed 's/^[ \t]*//')
# TOOLTIP=$(ps -eo %cpu,comm --sort=-%cpu | head -n 6 | sed '1d' | awk '{output = output sprintf("%.1f%%\t%s\\n", $1, $2)} END {printf "%s", output}')
# TOOLTIP=$(ps -eo %cpu,comm --sort=-%cpu | head -n 6 | sed '1d' | awk -v ncores=$(nproc) '{printf "%.1f%%\t%s\n", $1/ncores, $2}')
TOOLTIP=$(ps -eo %cpu,comm --sort=-%cpu | head -n 6 | sed '1d' | awk -v ncores=$(nproc) '{printf "%.1f%%\t%s\\n", $1/ncores, $2}')
# TOOLTIP=$(ps -eo %cpu,comm --sort=-%cpu | head -n 6 | sed '1d' | awk -v ncores=$(nproc) '{printf "%.1f%%\t%s\\n", $1/ncores, $2}')
# TOOLTIP=$(top -b -n 1 | sed '1,7d' | head -n 5 | awk '{output = output sprintf("%.1f%%\t%s\\n", $9, $12)} END {printf "%s", output}')
CLASS=""
@@ -18,4 +18,5 @@ else
CLASS="normal"
fi
echo "{\"text\":\"CPU: $TEXT\", \"tooltip\": \"$TOOLTIP\", \"class\":\"$CLASS\"}"
# echo "{\"text\":\"CPU: $TEXT\", \"tooltip\": \"$TOOLTIP\", \"class\":\"$CLASS\"}"
echo "{\"text\":\"CPU: $TEXT\", \"class\":\"$CLASS\"}"

31
waybar/scripts/disk_info.sh Executable file
View File

@@ -0,0 +1,31 @@
#!/bin/sh
if [ -z "$1" ]; then
echo "Usage: $0 <mountpoint>"
exit 1
fi
MOUNTPOINT=$1
# Get disk usage info
USED=$(df -h --output=used "$MOUNTPOINT" | sed '1d' | awk '{print $1}')
TOTAL=$(df -h --output=size "$MOUNTPOINT" | sed '1d' | awk '{print $1}')
PERCENTAGE=$(df --output=pcent "$MOUNTPOINT" | sed '1d' | tr -d '%' | awk '{print $1}')
# Set class based on usage
CLASS="normal"
if [ "$PERCENTAGE" -gt 95 ]; then
CLASS="max"
elif [ "$PERCENTAGE" -gt 80 ]; then
CLASS="high"
fi
# Create tooltip with more details
TOOLTIP=$(df -h "$MOUNTPOINT" | sed '1d' | awk '{printf "Used: %s\nTotal: %s\nFree: %s", $3, $2, $4}')
# Output JSON for Waybar using jq
jq -n -c \
--arg text "$1 $USED/$TOTAL" \
--arg tooltip "$TOOLTIP" \
--arg class "$CLASS" \
'{"text": $text, "tooltip": $tooltip, "class": $class}'

View File

@@ -1,6 +1,6 @@
#!/bin/sh
TOOLTIP=$(ps -eo rss,comm --sort=-rss | head -n 6 | sed '1d' | awk '{output = output sprintf("%.2f GB\t%s\\n", $1/1024/1024, $2)} END {printf "%s", output}')
# TOOLTIP=$(ps -eo rss,comm --sort=-rss | head -n 6 | sed '1d' | awk '{output = output sprintf("%.2f GB\t%s\\n", $1/1024/1024, $2)} END {printf "%s", output}')
TOTAL=$(awk '/MemTotal/ {printf "%.2f\n", $2/1024/1024}' /proc/meminfo)
USED=$(awk '/MemTotal/ {total=$2} /MemAvailable/ {available=$2} END {printf "%.2f\n", (total-available)/1024/1024}' /proc/meminfo)
RATIO=$(echo "$USED/ $TOTAL" | bc -l)
@@ -15,4 +15,5 @@ else
CLASS="normal"
fi
printf '{"text": "%s/%sGB", "tooltip": "%s", "class": "%s"}' "$USED" "$TOTAL" "$TOOLTIP" "$CLASS"
# printf '{"text": "%s/%sGB", "tooltip": "%s", "class": "%s"}' "$USED" "$TOTAL" "$TOOLTIP" "$CLASS"
printf '{"text": "%s/%sGB", "class": "%s"}' "$USED" "$TOTAL" "$CLASS"