Add community scripts for i3blocks
This commit is contained in:
47
.local/bin/i3scripts/contrib/cpu
Executable file
47
.local/bin/i3scripts/contrib/cpu
Executable file
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
################################
|
||||
# Shows info about the CPU
|
||||
#
|
||||
# Dependencies:
|
||||
# - [notify-send]
|
||||
#
|
||||
# @return {Number(%)}: CPU usage
|
||||
################################
|
||||
|
||||
dir=$(dirname $0)
|
||||
source $dir/util.sh
|
||||
|
||||
full=""
|
||||
short=""
|
||||
status=0
|
||||
|
||||
read cpu a b c previdle rest < /proc/stat
|
||||
prevtotal=$(calc "$a + $b + $c + $previdle")
|
||||
sleep 0.5
|
||||
read cpu a b c idle rest < /proc/stat
|
||||
total=$(calc "$a + $b + $c + $idle")
|
||||
|
||||
CPU=$(calc "100 * (($total - $prevtotal) - ($idle - $previdle)) / ($total - $prevtotal)")
|
||||
|
||||
full="$CPU%"
|
||||
short=$full
|
||||
|
||||
if [ $CPU -ge 90 ]; then
|
||||
status=33
|
||||
fi
|
||||
|
||||
case $BLOCK_BUTTON in
|
||||
|
||||
# right click: show packages
|
||||
3)
|
||||
n=16
|
||||
summary=$(ps -eo pcpu,pmem,pid,comm --sort=-pcpu | head -$n)
|
||||
notify-send "Top $n CPU-eaters" "$summary"
|
||||
;;
|
||||
|
||||
esac
|
||||
|
||||
echo $full
|
||||
echo $short
|
||||
exit $status
|
||||
Reference in New Issue
Block a user