gneral stuff
parent
2690f1bdd2
commit
25c9e69ad2
|
|
@ -1,8 +1,8 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Get percentage and remove the % sign cleanly
|
# Get percentage and remove the % sign cleanly
|
||||||
perc=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | awk '/percentage/ {gsub("%",""); print $2}')
|
perc=$(upower -i /org/freedesktop/UPower/devices/battery_BAT1 | awk '/percentage/ {gsub("%",""); print $2}')
|
||||||
state=$(upower -i /org/freedesktop/UPower/devices/battery_BAT0 | awk '/state/ {print $2}')
|
state=$(upower -i /org/freedesktop/UPower/devices/battery_BAT1 | awk '/state/ {print $2}')
|
||||||
|
|
||||||
# Check if values are not empty
|
# Check if values are not empty
|
||||||
if [ -z "$perc" ] || [ -z "$state" ]; then
|
if [ -z "$perc" ] || [ -z "$state" ]; then
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,21 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
DIR="${1:-$HOME/Pictures}"
|
VERBOSE=0
|
||||||
IMAGES=()
|
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
|
while IFS= read -r -d '' f; do
|
||||||
IMAGES+=("$f")
|
IMAGES+=("$f")
|
||||||
done < <(find "$DIR" -maxdepth 1 -type 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; }
|
[[ ${#IMAGES[@]} -eq 0 ]] && { echo "No images found in $DIR"; exit 1; }
|
||||||
|
|
||||||
INDEX=0
|
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; }
|
clear_images() { icat --clear; }
|
||||||
|
|
||||||
draw() {
|
draw() {
|
||||||
|
|
@ -37,19 +52,48 @@ draw() {
|
||||||
printf '\033[2J\033[H'
|
printf '\033[2J\033[H'
|
||||||
clear_images
|
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 "${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
|
tput cup $(( rows - 2 )) 0
|
||||||
printf ' [%d/%d] %s\n' $(( INDEX + 1 )) "$n" "$(basename "${IMAGES[$INDEX]}")"
|
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() {
|
set_wallpaper() {
|
||||||
local path="$1"
|
local path="$1" prev="$CURRENT_WALLPAPER"
|
||||||
hyprctl hyprpaper preload "$path" &>/dev/null &&
|
local out rc
|
||||||
hyprctl hyprpaper wallpaper ",$path" &>/dev/null
|
|
||||||
|
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() {
|
read_key() {
|
||||||
|
|
@ -65,7 +109,7 @@ read_key() {
|
||||||
|
|
||||||
old_stty=$(stty -g)
|
old_stty=$(stty -g)
|
||||||
trap 'stty "$old_stty"; clear_images; tput cnorm; printf "\033[2J\033[H"' EXIT
|
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
|
tput civis
|
||||||
|
|
||||||
draw
|
draw
|
||||||
|
|
@ -86,6 +130,7 @@ while true; do
|
||||||
else
|
else
|
||||||
tput cup $(( $(tput lines) - 1 )) 0
|
tput cup $(( $(tput lines) - 1 )) 0
|
||||||
printf ' Failed — is hyprpaper running?'
|
printf ' Failed — is hyprpaper running?'
|
||||||
|
(( VERBOSE )) && printf ' [see %s]' "$LOG"
|
||||||
fi ;;
|
fi ;;
|
||||||
q|Q) break ;;
|
q|Q) break ;;
|
||||||
esac
|
esac
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue