dotfiles/home/default/.local/bin/change-background
2023-05-03 21:19:35 +07:00

33 lines
1.2 KiB
Bash
Executable File

#!/bin/sh
# Location of link to wallpaper link.
bgloc="${XDG_DATA_HOME:-$HOME/.local/share}/bg"
bgaloc="${XDG_DATA_HOME:-$HOME/.local/share}/bga"
trueloc="$(readlink -f "$1")" &&
case "$(file --mime-type -b "$trueloc")" in
video/* ) ifinstalled mpvpaper && ln -sf "$trueloc" "$bgaloc" && notify-send -i "$bgaloc" "Changing wallpaper..." ;;
image/gif ) ifinstalled mpvpaper && ln -sf "$trueloc" "$bgaloc" && ln -sf "$trueloc" "$bgloc" && notify-send -i "$bgaloc" "Changing wallpaper..." ;;
image/* ) ln -sf "$trueloc" "$bgloc" && notify-send -i "$bgloc" "Changing wallpaper..."
if [[ -f "$bgaloc" ]]; then
rm $bgaloc
fi
;;
inode/directory ) ln -sf "$(find "$trueloc" -iregex '.*.\(jpg\|jpeg\|png\|gif\)' -type f | shuf -n 1)" "$bgloc" && notify-send -i "$bgloc" "Random Wallpaper chosen."
rm $bgaloc
;;
*) notify-send "🖼️ Error" "Not a valid image or directory." ; exit 1;;
esac
if [[ -f "$bgaloc" ]]; then
killall swaybg >/dev/null 2>&1
killall mpvpaper >/dev/null 2>&1
sleep 1 && setsid -f mpvpaper -f -o 'no-audio loop --panscan=1' '*' $bgaloc >/dev/null 2>&1
exit 0
elif [[ -f "$bgloc" ]]; then
killall swaybg >/dev/null 2>&1
killall mpvpaper >/dev/null 2>&1
sleep 1 && setsid -f swaybg -m fill -i $bgloc >/dev/null 2>&1
fi
exit 0