34 lines
1.3 KiB
Bash
Executable file
34 lines
1.3 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
date=$(date +'%a %Y-%m-%d %X')
|
|
battery=$(acpi -b | cut -d , -f 2 | cut -c 2-)
|
|
network_name=$(iwgetid -r)
|
|
wp_output=$(wpctl get-volume @DEFAULT_AUDIO_SINK@)
|
|
|
|
top_output=$(top -bn 1 | grep -iA 1 -m 1 cpu)
|
|
|
|
cpu_usage=$(grep -oEm 1 '[[:digit:]]?[[:digit:]]{2}\.[[:digit:]]+ id' <<< "$top_output")
|
|
cpu_usage=$(bc <<< "100 - ${cpu_usage% id}")
|
|
|
|
total_ram=$(grep -oEm 1 '[[:digit:]]+\.[[:digit:]]+ total' <<< "$top_output")
|
|
used_ram=$(grep -oEm 1 '[[:digit:]]+\.[[:digit:]]+ used' <<< "$top_output")
|
|
ram_usage=$(bc <<< "scale = 3; (${used_ram% used} / ${total_ram% total}) * 100;")
|
|
|
|
# swaymsg -t get_inputs doesn't return 2 letter country codes for all languages...
|
|
current_kb_layout=$(swaymsg -t get_inputs | grep -m 1 'xkb_active_layout_name' | \
|
|
sed 's/Lithuanian/LT/' | grep -oEm 1 '[[:upper:]]{2}')
|
|
|
|
if grep "MUTED" <<< "$wp_output"; then
|
|
volume=0.00
|
|
else
|
|
volume=$(cut -c 9-12 <<< "$wp_output")
|
|
volume=$(bc <<< "$volume * 100")
|
|
fi
|
|
|
|
if [[ "$network_name" ]]; then
|
|
printf "%s | RAM: %.1f%% | CPU: %.1f%% | Volume: %.0f%% | Battery: %s | Connected to: %s | %s" \
|
|
"$current_kb_layout" "$ram_usage" "$cpu_usage" "$volume" "$battery" "$network_name" "$date"
|
|
else
|
|
printf "%s | RAM: %.1f%% | CPU: %.1f%% | Volume: %.0f%% | Battery: %s | Not connected to WiFi | %s" \
|
|
"$current_kb_layout" "$ram_usage" "$cpu_usage" "$volume" "$battery" "$date"
|
|
fi
|