diff --git a/README.md b/README.md index 21188f1..89c0ea9 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,9 @@ Install `i3blocks` and clone this repo to `~/.config/i3blocks`. Remember to back - [ ] fix ip not showing sometimes - [ ] swap - [ ] audio -- [ ] battery +- [x] battery - [ ] cpu - [ ] wifi/ethernet/bluetooth - [ ] external storage mount - [ ] ethernet bandwith +- [x] same color palette diff --git a/battery b/battery new file mode 100755 index 0000000..3f5135b --- /dev/null +++ b/battery @@ -0,0 +1,40 @@ +#!/bin/bash + +[[ ${BLOCK_INSTANCE} == '' ]] && BATTERY=0 || BATTERY=${BLOCK_INSTANCE} +cat /sys/class/power_supply/BAT${BATTERY}/uevent | gawk -F '=' ' + /POWER_SUPPLY_STATUS=/ { + status=$2 + } + /POWER_SUPPLY_ENERGY_FULL=/ { + efull=$2 + } + /POWER_SUPPLY_ENERGY_NOW=/ { + enow=$2 + } + END { + charge=enow/efull*100 + if (status == "Discharging") { + status="↓" + } else if (status == "Charging") { + status="↑" + } else { + status="" + } + printf("%s%d%", status, charge) + print("\n") + if (charge < 20) { + print("#FF0000\n") + } else if (charge < 40) { + print("#FFAE00\n") + } else if (charge < 60) { + print("#FFF600\n") + } else if (charge < 85) { + print("#A8FF00\n") + } else { + print("#04B431\n") + } + if (charge < 5) { + exit 33 + } + } +' diff --git a/config b/config index f5465cb..aa12a35 100644 --- a/config +++ b/config @@ -9,4 +9,7 @@ interval=5 [storage] [ip] interval=once +[battery] +[battery] +instance=1 [datetime] diff --git a/ram b/ram index afa5915..3bab68b 100755 --- a/ram +++ b/ram @@ -1,14 +1,28 @@ #!/bin/bash gawk ' - /^MemFree:/ { + /^MemAvailable:/ { mfg=$2/1024^2 - mfm=$2/1024 - } END { - if (mfg > 2) { printf("%.1f GB", mfg) } - else { printf( "%.0f MB", mfm ) } + mfm=$2/1024 + } + END { + if (mfg > 2) { + printf("%.1f GB", mfg) + } else { + printf("%.0f MB", mfm) + } print("\n") - if (mfg > 4) { print("#04B431\n") } - else if (mfg > 2) { print("#FFA500\n") } - else { print("#FF0000\n") } - }' /proc/meminfo - + if (mfg > 20) { + print("#04B431\n") + } else if (mfg > 4) { + print("#A8FF00\n") + } else if (mfg > 3) { + print("#FFF600\n") + } else if (mfg > 2) { + print("#FFAE00\n") + } else if (mfg > 1) { + print("#FF0000\n") + } else { + exit 33 + } + } +' /proc/meminfo diff --git a/storage b/storage index 6a5ddb0..368f80d 100755 --- a/storage +++ b/storage @@ -5,12 +5,24 @@ df | gawk ' sfm=$4/1024 } END { - if (sfg > 5) { printf("%.1f GB", sfg) } - else { printf( "%.0f MB", sfm ) } + if (sfg > 5) { + printf("%.1f GB", sfg) + } else { + printf("%.0f MB", sfm) + } print("\n") - if (sfg > 15) { print("#04B431\n") } - else if (sfg > 5) { print("#FFA500\n") } - else if (sfg > 1) { print("#FF0000\n") } - else { exit 33 } - }' - + if (sfg > 20) { + print("#04B431\n") + } else if (sfg > 15) { + print("#A8FF00\n") + } else if (sfg > 10) { + print("#FFF600\n") + } else if (sfg > 5) { + print("#FFAE00\n") + } else if (sfg > 1) { + print("#FF0000\n") + } else { + exit 33 + } + } +'