aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikkel Thestrup <mikkel@mithe.dk>2026-01-25 15:38:58 +0100
committerMikkel Thestrup <mikkel@mithe.dk>2026-01-27 22:56:12 +0100
commit35536c401016c0ac69c164a65d2c31b74992a808 (patch)
tree5e956602dd23b5ab32dc3cb311be151dfdd10ba4
downloadscripts-35536c401016c0ac69c164a65d2c31b74992a808.tar.gz
scripts-35536c401016c0ac69c164a65d2c31b74992a808.zip
Initial commit
Diffstat (limited to '')
-rw-r--r--Makefile23
-rw-r--r--README.md0
-rwxr-xr-xbattery-bar.sh128
-rwxr-xr-xprompt.sh8
-rwxr-xr-xwallpaper-picker.sh30
-rwxr-xr-xwallpaper.sh12
6 files changed, 201 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..a6e9a35
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,23 @@
+INSTALL_DIR = /usr/local/bin
+
+SCRIPTS = $(wildcard *.sh)
+
+INSTALL_SCRIPTS = $(SCRIPTS:.sh=)
+
+install:
+ @for script in $(SCRIPTS); do \
+ if [ -f $$script ]; then \
+ install_name=$$(basename $$script .sh); \
+ cp $$script $(INSTALL_DIR)/$$install_name; \
+ chmod +x $(INSTALL_DIR)/$$install_name; \
+ fi \
+ done
+
+uninstall:
+ @for script in $(INSTALL_SCRIPTS); do \
+ if [ -f $(INSTALL_DIR)/$$script ]; then \
+ rm -f $(INSTALL_DIR)/$$script; \
+ fi \
+ done
+
+.PHONY: install uninstall
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/README.md
diff --git a/battery-bar.sh b/battery-bar.sh
new file mode 100755
index 0000000..df34643
--- /dev/null
+++ b/battery-bar.sh
@@ -0,0 +1,128 @@
+#!/bin/sh
+# Battery status display script for systems with /sys/class/power_supply
+
+SYS_BASE="/sys/class/power_supply"
+
+# Read battery energy values
+# Returns: "energy_now energy_full" or exits with error
+read_battery() {
+ bat="$1"
+ base="$SYS_BASE/$bat"
+
+ [ -r "$base/energy_now" ] || return 1
+ [ -r "$base/energy_full" ] || return 1
+
+ energy_now=$(cat "$base/energy_now" 2>/dev/null) || return 1
+ energy_full=$(cat "$base/energy_full" 2>/dev/null) || return 1
+
+ # Validate numeric values
+ case "$energy_now" in
+ ''|*[!0-9]*) return 1 ;;
+ esac
+ case "$energy_full" in
+ ''|*[!0-9]*) return 1 ;;
+ esac
+
+ echo "$energy_now $energy_full"
+}
+
+# Determine battery state symbol based on status of all batteries
+battery_state_symbol() {
+ charging=0
+ discharging=0
+ full=0
+ not_charging=0
+ bat_found=0
+
+ for bat in BAT0 BAT1; do
+ status_path="$SYS_BASE/$bat/status"
+ [ -r "$status_path" ] || continue
+
+ bat_found=1
+ status=$(cat "$status_path" 2>/dev/null | tr -d '\n')
+ case "$status" in
+ Charging)
+ charging=1
+ ;;
+ Discharging)
+ discharging=1
+ ;;
+ Full)
+ full=1
+ ;;
+ "Not charging")
+ not_charging=1
+ ;;
+ esac
+ done
+
+ # No batteries found
+ [ "$bat_found" -eq 0 ] && echo " " && return 1
+
+ # Priority: charging > discharging > not_charging > full
+ # If any battery is charging, show charging
+ [ "$charging" -eq 1 ] && echo "⁺" && return 0
+ # If any battery is discharging, show discharging
+ [ "$discharging" -eq 1 ] && echo "⁻" && return 0
+ # If any battery is not charging (plugged but not charging)
+ [ "$not_charging" -eq 1 ] && echo "˜" && return 0
+ # All batteries full
+ [ "$full" -eq 1 ] && echo "=" && return 0
+
+ # Unknown status
+ echo " "
+ return 1
+}
+
+battery_bar() {
+ percent="$1"
+
+ [ "$percent" -lt 0 ] && percent=0
+ [ "$percent" -gt 100 ] && percent=100
+
+ filled=$((percent / 10))
+ empty=$((10 - filled))
+
+ bar=""
+ i=0
+ while [ "$i" -lt "$filled" ]; do
+ bar="${bar}█"
+ i=$((i + 1))
+ done
+
+ i=0
+ while [ "$i" -lt "$empty" ]; do
+ bar="${bar}░"
+ i=$((i + 1))
+ done
+
+ echo "$bar"
+}
+
+battery_summary() {
+ total_now=0
+ total_full=0
+ bat_count=0
+
+ for bat in BAT0 BAT1; do
+ vals=$(read_battery "$bat") || continue
+ set -- $vals
+ total_now=$((total_now + $1))
+ total_full=$((total_full + $2))
+ bat_count=$((bat_count + 1))
+ done
+
+ if [ "$bat_count" -eq 0 ] || [ "$total_full" -eq 0 ]; then
+ echo "No battery"
+ return 1
+ fi
+
+ percent=$(( (total_now * 100 + total_full / 2) / total_full ))
+
+ bar=$(battery_bar "$percent")
+ symbol=$(battery_state_symbol)
+
+ echo "▕${bar}▏${percent}${symbol}"
+}
+
+battery_summary
diff --git a/prompt.sh b/prompt.sh
new file mode 100755
index 0000000..df95196
--- /dev/null
+++ b/prompt.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+############################################################
+# Utility for prompting user affirmation before executing a
+# command.
+# $1 - Prompt message
+# $2 - Command to execute if affirmed
+############################################################
+[ $(echo "No\nYes" | dmenu -i -p "$1") = "Yes" ] && $2
diff --git a/wallpaper-picker.sh b/wallpaper-picker.sh
new file mode 100755
index 0000000..7b26563
--- /dev/null
+++ b/wallpaper-picker.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+# Program for picking wallpaper using Dmenu.
+
+FOLDER="$HOME/pictures/wallpaper"
+
+menu() {
+ CHOICE=$(ls "$FOLDER" | dmenu -l 15 -i -p "Wallpaper: ")
+
+ case "$CHOICE" in
+ *.*)
+ wallpaper "$FOLDER/$CHOICE"
+ ;;
+ *)
+ exit 0
+ ;;
+
+ esac
+}
+
+case "$#" in
+ 0)
+ menu
+ ;;
+ 1)
+ wallpaper "$1"
+ ;;
+ *)
+ exit 0
+ ;;
+esac
diff --git a/wallpaper.sh b/wallpaper.sh
new file mode 100755
index 0000000..27130ea
--- /dev/null
+++ b/wallpaper.sh
@@ -0,0 +1,12 @@
+#!/bin/sh
+############################################################
+# Utility for changing wallpaper and generating colorscheme.
+# $1 - Picture to use as wallpaper
+############################################################
+
+wallust run $1
+feh --bg-fill $1
+xrdb -merge ~/.Xresources
+
+# Send st signal to reload colors from Xresources
+pidof st | xargs kill -s USR1