aboutsummaryrefslogtreecommitdiffstats
path: root/basics/.local/bin
diff options
context:
space:
mode:
Diffstat (limited to 'basics/.local/bin')
-rwxr-xr-xbasics/.local/bin/battery-monitor41
-rwxr-xr-xbasics/.local/bin/edit-config6
-rwxr-xr-xbasics/.local/bin/locate-config24
3 files changed, 71 insertions, 0 deletions
diff --git a/basics/.local/bin/battery-monitor b/basics/.local/bin/battery-monitor
new file mode 100755
index 0000000..ff1ef8b
--- /dev/null
+++ b/basics/.local/bin/battery-monitor
@@ -0,0 +1,41 @@
+battery_level=`acpi -b | cut -d ' ' -f 4 | grep -o '[0-9]*'`
+battery_state=$(acpi | grep 'Battery' | sed 's/Battery\s[0-9]*: //' | sed 's/, [0-9][0-9]*\%.*//')
+battery_remaining=$(acpi | grep -oh '[0-9:]* remaining' | sed 's/:\w\w remaining$/ Minutes/' | sed 's/00://' | sed 's/:/h /')
+
+if [ ! -f "/tmp/.battery" ]; then
+ echo "$battery_level" > /tmp/.battery
+ echo "$battery_state" >> /tmp/.battery
+ exit
+fi
+
+previous_battery_level=$(cat /tmp/.battery | head -n 1)
+previous_battery_state=$(cat /tmp/.battery | tail -n 1)
+echo "$battery_level" > /tmp/.battery
+echo "$battery_state" >> /tmp/.battery
+
+checkBatteryLevel() {
+ if [ $battery_state != "Discharging" ] || [ "${battery_level}" == "${previous_battery_level}" ]; then
+ exit
+ fi
+
+ if [ $battery_level -le 3 ]; then
+ sudo systemctl suspend
+ elif [ $battery_level -le 5 ]; then
+ notify-send "Low Battery" "Your computer will suspend soon unless plugged into a power outlet." -u critical
+ elif [ $battery_level -le 10 ]; then
+ notify-send "Low Battery" "${battery_level}% (${battery_remaining}) of battery remaining." -u normal
+ fi
+}
+
+checkBatteryStateChange() {
+ if [ "$battery_state" != "Discharging" ] && [ "$previous_battery_state" == "Discharging" ]; then
+ notify-send "Charging" "Battery is now plugged in." -u low
+ fi
+
+ if [ "$battery_state" == "Discharging" ] && [ "$previous_battery_state" != "Discharging" ]; then
+ notify-send "Power Unplugged" "Your computer has been disconnected from power." -u low
+ fi
+}
+
+checkBatteryStateChange
+checkBatteryLevel \ No newline at end of file
diff --git a/basics/.local/bin/edit-config b/basics/.local/bin/edit-config
new file mode 100755
index 0000000..7d1baae
--- /dev/null
+++ b/basics/.local/bin/edit-config
@@ -0,0 +1,6 @@
+#/bin/sh
+
+FILE=$(locate-config)
+[ -z "$FILE" ] && exit 1
+
+$EDITOR $FILE
diff --git a/basics/.local/bin/locate-config b/basics/.local/bin/locate-config
new file mode 100755
index 0000000..d798a39
--- /dev/null
+++ b/basics/.local/bin/locate-config
@@ -0,0 +1,24 @@
+#! /usr/bin/env bash
+
+set -e
+
+CONFIG_FILES=`ls -1 ~/.local/share/config-files | cut -d "" -f 1 | sort -d`
+CONFIG_ARRAY=(`find ~/.local/share/config-files/ -maxdepth 1 -mindepth 1 -print0 | sort -z | xargs -r0 echo`)
+
+INDEX=`echo "$CONFIG_FILES" | rofi -dmenu -format "i" -no-custom -mesg "Find config file for..."`
+[ -z "$INDEX" ] && exit 1
+SOURCE=${CONFIG_ARRAY[$INDEX]}
+#echo "$CONFIG_FILES"
+#for item in ${CONFIG_ARRAY[*]}
+#do
+# printf " %s\n" $item
+#done
+# (https://stackoverflow.com/questions/59895/get-the-source-directory-of-a-bash-script-from-within-the-script-itself)
+while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
+ DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
+ SOURCE="$(readlink "$SOURCE")"
+ [[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
+done
+DIR="$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )"
+
+echo $SOURCE