aboutsummaryrefslogtreecommitdiffstats
path: root/basics/.local
diff options
context:
space:
mode:
authorPeter Son Struschka <me@peter-struschka.com>2020-02-02 12:50:32 +0800
committerPeter Son Struschka <me@peter-struschka.com>2020-02-02 12:50:32 +0800
commitf2b18aab5a84d04a36f4194473680ad70bdb5578 (patch)
treee9db24237556f25832811d224bcb7898f22d5d1a /basics/.local
parent2bb9010d2e613206ce3d476dbea81eb9a56f3c66 (diff)
downloaddotfiles-f2b18aab5a84d04a36f4194473680ad70bdb5578.tar.gz
dotfiles-f2b18aab5a84d04a36f4194473680ad70bdb5578.tar.bz2
dotfiles-f2b18aab5a84d04a36f4194473680ad70bdb5578.tar.lz
dotfiles-f2b18aab5a84d04a36f4194473680ad70bdb5578.tar.xz
dotfiles-f2b18aab5a84d04a36f4194473680ad70bdb5578.tar.zst
dotfiles-f2b18aab5a84d04a36f4194473680ad70bdb5578.zip
script to find and edit config files
Diffstat (limited to 'basics/.local')
-rwxr-xr-xbasics/.local/bin/battery-monitor41
-rwxr-xr-xbasics/.local/bin/edit-config6
-rwxr-xr-xbasics/.local/bin/locate-config24
l---------basics/.local/share/config-files/alacritty1
l---------basics/.local/share/config-files/dotfiles1
l---------basics/.local/share/config-files/dunst1
l---------basics/.local/share/config-files/kitty1
l---------basics/.local/share/config-files/ranger1
l---------basics/.local/share/config-files/rofi1
9 files changed, 77 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
diff --git a/basics/.local/share/config-files/alacritty b/basics/.local/share/config-files/alacritty
new file mode 120000
index 0000000..2f6fb52
--- /dev/null
+++ b/basics/.local/share/config-files/alacritty
@@ -0,0 +1 @@
+../../../.config/alacritty/alacritty.yml \ No newline at end of file
diff --git a/basics/.local/share/config-files/dotfiles b/basics/.local/share/config-files/dotfiles
new file mode 120000
index 0000000..11a54ed
--- /dev/null
+++ b/basics/.local/share/config-files/dotfiles
@@ -0,0 +1 @@
+../../../../ \ No newline at end of file
diff --git a/basics/.local/share/config-files/dunst b/basics/.local/share/config-files/dunst
new file mode 120000
index 0000000..0faa1f8
--- /dev/null
+++ b/basics/.local/share/config-files/dunst
@@ -0,0 +1 @@
+../../../.config/dunst/dunstrc \ No newline at end of file
diff --git a/basics/.local/share/config-files/kitty b/basics/.local/share/config-files/kitty
new file mode 120000
index 0000000..71c3f1a
--- /dev/null
+++ b/basics/.local/share/config-files/kitty
@@ -0,0 +1 @@
+../../../.config/kitty/kitty.conf \ No newline at end of file
diff --git a/basics/.local/share/config-files/ranger b/basics/.local/share/config-files/ranger
new file mode 120000
index 0000000..5ecd95a
--- /dev/null
+++ b/basics/.local/share/config-files/ranger
@@ -0,0 +1 @@
+../../../.config/ranger/rc.conf \ No newline at end of file
diff --git a/basics/.local/share/config-files/rofi b/basics/.local/share/config-files/rofi
new file mode 120000
index 0000000..2695e7e
--- /dev/null
+++ b/basics/.local/share/config-files/rofi
@@ -0,0 +1 @@
+../../../.config/rofi/config \ No newline at end of file