From 811fa21a9df0c136cafab935b6882b7541a22203 Mon Sep 17 00:00:00 2001 From: David Runge Date: Fri, 11 Mar 2016 10:42:47 +0100 Subject: bin/get_*: Adding helper scripts to be used in tmux. --- bin/get_battery_status | 27 +++++++++++++++++++++++++++ bin/get_cpu_status | 10 ++++++++++ bin/get_load | 8 ++++++++ 3 files changed, 45 insertions(+) create mode 100755 bin/get_battery_status create mode 100755 bin/get_cpu_status create mode 100755 bin/get_load (limited to 'bin') diff --git a/bin/get_battery_status b/bin/get_battery_status new file mode 100755 index 0000000..5ad18ce --- /dev/null +++ b/bin/get_battery_status @@ -0,0 +1,27 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' + +acpi_output="" +battery_number=0 +battery_percentage=0 +battery_remaining="" + +if [ -x /usr/bin/acpi ]; then + acpi_output=$(/usr/bin/acpi -b) + battery_number=$(echo $acpi_output|cut -d':' -f1|cut -d' ' -f2) + battery_state=$(echo $acpi_output|cut -d' ' -f3) + battery_state=${battery_state%","} + battery_percentage=$(echo $acpi_output|cut -d' ' -f4) + battery_percentage=${battery_percentage%","} + battery_percentage=${battery_percentage%"%"} + if [ $battery_state = "Discharging" ]; then + battery_remaining=$(echo $acpi_output|cut -d' ' -f5) + echo "$battery_percentage% ($battery_remaining)" + else + echo "$battery_percentage%" + fi +else + exit 1 +fi + diff --git a/bin/get_cpu_status b/bin/get_cpu_status new file mode 100755 index 0000000..2aece18 --- /dev/null +++ b/bin/get_cpu_status @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' + +proc_output="" + +proc_output=$(grep 'cpu ' /proc/stat | awk '{usage=($2+$4)*100/($2+$4+$5)} END {printf("%5.1f", usage)}') +proc_output=${proc_output#" "} + +echo "$proc_output%" diff --git a/bin/get_load b/bin/get_load new file mode 100755 index 0000000..7991d26 --- /dev/null +++ b/bin/get_load @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' + +uptime_output=$(uptime| cut -d',' -f4,5,6|cut -d':' -f2) +uptime_output=${uptime_output#" "} + +echo "$uptime_output" -- cgit v1.2.3-70-g09d2