▲ 0 r/i3wm
gtk2 failed to compile in a chroot today, so I made deepseek spit this out, so I could uninstall nitrogen.
#!/usr/bin/env bash
set -euo pipefail
DATA_DIR="${XDG_CONFIG_HOME:-$HOME/.config}/xwp"
mkdir -p "$DATA_DIR"
# Save a single output's arguments
save_output() {
local output="$1"
shift
printf "%s\n" "$@" > "$DATA_DIR/last_$output"
}
# Parse command line arguments (as array) and save per output
save_per_output() {
local args=("$@")
local current_out="" current_args=()
while (($#)); do
case "$1" in
--output)
# Save previous output if any
if [[ -n "$current_out" ]]; then
save_output "$current_out" "${current_args[@]}"
fi
shift
if (($# == 0)); then
echo "Error: --output missing argument" >&2
exit 1
fi
current_out="$1"
current_args=()
;;
*)
if [[ -z "$current_out" ]]; then
current_out="_default"
fi
current_args+=("$1")
;;
esac
shift
done
# Save the last output
if [[ -n "$current_out" ]]; then
save_output "$current_out" "${current_args[@]}"
fi
}
# Restore all saved outputs
restore_all() {
local cmd=()
for file in "$DATA_DIR"/last_*; do
[[ -f "$file" ]] || continue
out="${file##*/last_}"
mapfile -t stored < "$file"
(( ${#stored[@]} == 0 )) && continue
cmd+=("--output" "$out" "${stored[@]}")
done
if (( ${#cmd[@]} == 0 )); then
echo "Error: No saved wallpaper settings." >&2
exit 1
fi
xwallpaper "${cmd[@]}"
}
# Save preset
save_preset() {
local n="$1"
[[ -n "$n" ]] || { echo "Usage: --save-preset N" >&2; exit 1; }
local full_cmd=()
for file in "$DATA_DIR"/last_*; do
[[ -f "$file" ]] || continue
out="${file##*/last_}"
mapfile -t stored < "$file"
full_cmd+=("--output" "$out" "${stored[@]}")
done
(( ${#full_cmd[@]} == 0 )) && { echo "No current wallpaper to save." >&2; exit 1; }
printf "%s\n" "${full_cmd[@]}" > "$DATA_DIR/preset_$n"
}
# Load preset
load_preset() {
local n="$1"
local preset_file="$DATA_DIR/preset_$n"
[[ -f "$preset_file" ]] || { echo "Error: Preset $n not found." >&2; exit 1; }
mapfile -t full_cmd < "$preset_file"
xwallpaper "${full_cmd[@]}"
save_per_output "${full_cmd[@]}"
}
# List presets
list_presets() {
local found=0
for f in "$DATA_DIR"/preset_*; do
[[ -f "$f" ]] && echo "Preset ${f##*_}" && found=1
done
(( found == 0 )) && echo "No presets saved."
}
# Main
if [[ $# -eq 0 ]]; then
cat <<EOF
Usage: $0 [--restore | --save-preset N | --preset N | --list-presets | xwallpaper-args]
EOF
exit 1
fi
case "$1" in
--restore) restore_all ;;
--save-preset) shift; save_preset "$1" ;;
--preset) shift; load_preset "$1" ;;
--list-presets) list_presets ;;
*)
if xwallpaper "$@"; then
# Convert "$@" to array to pass to function (preserves args with spaces)
save_per_output "$@"
else
echo "xwallpaper command failed" >&2
exit 1
fi
;;
esac
i3 config example:
# SET WALLPAPERS
# SUPER+R
set $wallpapers [s]elect for 0 | [S]elect for 1 \
| select-presets: [`-9] | save presets [(shift)3-9] \
[Escape] [Enter] or [Space] to exit
mode "$wallpapers" {
bindsym s exec \
alacritty --class wllppr -e \
~/.config/i3/scripts/wllppr;\
mode default
bindsym shift+s exec \
alacritty --class wllppr -e \
~/.config/i3/scripts/wllppr1;\
mode default
bindsym grave exec \
xwp --preset 0
bindsym 1 exec \
xwp --preset 1
bindsym 2 exec \
xwp --preset 2
bindsym 3 exec \
xwp --preset 3
bindsym 4 exec \
xwp --preset 4
bindsym 5 exec \
xwp --preset 5
bindsym 6 exec \
xwp --preset 6
bindsym 7 exec \
xwp --preset 7
bindsym 8 exec \
xwp --preset 8
bindsym 9 exec \
xwp --preset 9
bindsym shift+numbersign exec \
xwp --save-preset 3; mode default
bindsym shift+dollar exec \
xwp --save-preset 4; mode default
bindsym shift+percent exec \
xwp --save-preset 5; mode default
bindsym shift+asciicircum exec \
xwp --save-preset 6; mode default
bindsym shift+ampersand exec \
xwp --save-preset 7; mode default
bindsym shift+asterisk exec \
xwp --save-preset 8; mode default
bindsym shift+parenleft exec \
xwp --save-preset 9; mode default
bindsym Escape mode default
bindsym Enter mode default
bindsym space mode default
bindsym $mod+r mode default
}
u/Kitchen_Office8072 — 27 days ago