gneral stuff

main
The_miro 2026-05-09 17:22:55 +02:00
parent 2690f1bdd2
commit 25c9e69ad2
2 changed files with 57 additions and 12 deletions

View File

@ -1,8 +1,8 @@
#!/bin/bash
# Get percentage and remove the % sign cleanly
perc=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | awk '/percentage/ {gsub("%",""); print $2}')
state=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | awk '/state/ {print $2}')
perc=$(upower -i /org/freedesktop/UPower/devices/battery_BAT1 | awk '/percentage/ {gsub("%",""); print $2}')
state=$(upower -i /org/freedesktop/UPower/devices/battery_BAT1 | awk '/state/ {print $2}')
# Check if values are not empty
if [ -z "$perc" ] || [ -z "$state" ]; then

View File

@ -1,8 +1,21 @@
#!/usr/bin/env bash
DIR="${1:-$HOME/Pictures}"
IMAGES=()
VERBOSE=0
DIR=""
while [[ $# -gt 0 ]]; do
case "$1" in
-v|--verbose) VERBOSE=1 ;;
*) DIR="$1" ;;
esac
shift
done
DIR="${DIR:-$HOME/Pictures}"
LOG=""
(( VERBOSE )) && LOG="/tmp/wallpaper-picker-$$.log"
IMAGES=()
while IFS= read -r -d '' f; do
IMAGES+=("$f")
done < <(find "$DIR" -maxdepth 1 -type f \
@ -14,9 +27,11 @@ done < <(find "$DIR" -maxdepth 1 -type f \
[[ ${#IMAGES[@]} -eq 0 ]] && { echo "No images found in $DIR"; exit 1; }
INDEX=0
CURRENT_WALLPAPER=""
icat() { kitty +kitten icat --stdin=no --silent "$@" 2>/dev/null; }
vlog() { (( VERBOSE )) && printf '%s\n' "$*" >> "$LOG"; }
icat() { kitty +kitten icat --stdin=no --silent --transfer-mode=memory "$@" 2>/dev/null; }
clear_images() { icat --clear; }
draw() {
@ -37,19 +52,48 @@ draw() {
printf '\033[2J\033[H'
clear_images
icat --place "${side_w}x${img_h}@0x0" "${IMAGES[$prev]}"
icat --place "${side_w}x${img_h}@0x0" "${IMAGES[$prev]}"
icat --place "${center_w}x${img_h}@${center_x}x0" "${IMAGES[$INDEX]}"
icat --place "${side_w}x${img_h}@${next_x}x0" "${IMAGES[$next]}"
icat --place "${side_w}x${img_h}@${next_x}x0" "${IMAGES[$next]}"
tput cup $(( rows - 2 )) 0
printf ' [%d/%d] %s\n' $(( INDEX + 1 )) "$n" "$(basename "${IMAGES[$INDEX]}")"
printf ' h/←: prev l/→: next Enter: set wallpaper q: quit'
local hints=' h/←: prev l/→: next Enter: set wallpaper q: quit'
(( VERBOSE )) && hints+=" [log: $LOG]"
printf '%s' "$hints"
}
set_wallpaper() {
local path="$1"
hyprctl hyprpaper preload "$path" &>/dev/null &&
hyprctl hyprpaper wallpaper ",$path" &>/dev/null
local path="$1" prev="$CURRENT_WALLPAPER"
local out rc
vlog "=== set_wallpaper: $path ==="
out=$(hyprctl hyprpaper preload "$path" 2>&1); rc=$?
vlog "preload exit=$rc out=$out"
# Don't bail on preload failure — image may already be preloaded
local monitors_out ok=0
monitors_out=$(hyprctl monitors 2>&1)
vlog "monitors: $monitors_out"
while IFS= read -r mon; do
out=$(hyprctl hyprpaper wallpaper "$mon,$path" 2>&1); rc=$?
vlog "wallpaper $mon exit=$rc out=$out"
(( rc == 0 )) && ok=1
done < <(printf '%s\n' "$monitors_out" | awk '/^Monitor /{print $2}')
if (( ok == 0 )); then
vlog "FAILED: no monitor set"
return 1
fi
CURRENT_WALLPAPER="$path"
if [[ -n "$prev" && "$prev" != "$path" ]]; then
out=$(hyprctl hyprpaper unload "$prev" 2>&1); rc=$?
vlog "unload prev exit=$rc out=$out"
fi
return 0
}
read_key() {
@ -65,7 +109,7 @@ read_key() {
old_stty=$(stty -g)
trap 'stty "$old_stty"; clear_images; tput cnorm; printf "\033[2J\033[H"' EXIT
stty -echo -icanon min 1 time 0
stty -echo -icanon -icrnl min 1 time 0
tput civis
draw
@ -86,6 +130,7 @@ while true; do
else
tput cup $(( $(tput lines) - 1 )) 0
printf ' Failed — is hyprpaper running?'
(( VERBOSE )) && printf ' [see %s]' "$LOG"
fi ;;
q|Q) break ;;
esac