Unix3r

Build. Break. Learn. Repeat.

Starting0%
Skip to content

unix3r/dotfiles

Public
main
U Unix3r Initial commit: sway + waybar dotfiles (Catppuccin Mocha) eb290df
47 lines · 1.5 KB Raw History
1#!/usr/bin/env bash
2# wallpaper.sh restore|random|pick|set <file>
3# Wallpapers are read from $WALLPAPER_DIR (default ~/Pictures/Wallpapers),
4# falling back to the wallpapers/ folder shipped with these dotfiles.
5source "$(dirname "$0")/_lib.sh"
6
7state="${XDG_STATE_HOME:-$HOME/.local/state}/dotfiles/wallpaper"
8mkdir -p "$(dirname "$state")"
9fallback_color='#1e1e2e'
10
11dirs=("${WALLPAPER_DIR:-$HOME/Pictures/Wallpapers}")
12repo_walls="$(dirname "$(readlink -f "$HOME/.config/sway")")/../wallpapers"
13[[ -d $repo_walls ]] && dirs+=("$(readlink -f "$repo_walls")")
14
15list_walls() {
16 find "${dirs[@]}" -maxdepth 2 -type f \
17 \( -iname '*.png' -o -iname '*.jpg' -o -iname '*.jpeg' -o -iname '*.webp' \) 2>/dev/null
18}
19
20apply() {
21 local img=$1
22 pkill -x swaybg 2>/dev/null
23 if [[ -f $img ]]; then
24 echo "$img" > "$state"
25 swaybg -m fill -i "$img" >/dev/null 2>&1 &
26 else
27 swaybg -c "$fallback_color" >/dev/null 2>&1 &
28 fi
29 disown
30}
31
32case ${1:-restore} in
33 restore)
34 img=$(cat "$state" 2>/dev/null)
35 [[ -f $img ]] || img=$(list_walls | head -n1)
36 apply "$img" ;;
37 random)
38 img=$(list_walls | shuf -n1)
39 apply "$img"
40 [[ -n $img ]] && notify wall preferences-desktop-wallpaper "Wallpaper" "$(basename "$img")" ;;
41 pick)
42 img=$(list_walls | sort | menu "Wallpaper" --width 700 --height 400) || exit 0
43 apply "$img" ;;
44 set)
45 apply "$(readlink -f "$2")" ;;
46 *) echo "usage: $0 restore|random|pick|set <file>"; exit 1 ;;
47esac