#!/usr/bin/env bash set -euo pipefail SCRIPT=$(basename "$0") CONFIG="${XDG_CONFIG_HOME:-$HOME/.config}" VCONSOLE_UPDATE="$HOME/.local/bin/vconsole-colors.sh" WALLPAPER="${CONFIG}/hypr/wallpaper" QUIET_MODE=false SKIP_VCONSOLE=false SKIP_INITRAMFS=false show_help() { cat < A script to update system theme based on a wallpaper image. Options: -h, --help Show this help message and exit -q, --quiet Quiet mode: Suppress output to the terminal -n Skip prompting to regenerate initramfs -nn Skip prompting to update vconsole.conf Examples: $0 /path/to/image/sunset.jpg # Normal theme update $0 -q ~/wallpapers/night.jpg # Quiet mode theme update $0 -q -n ~/Downloads/nature.jpg # Combine quiet mode and skip initramfs Requirements: - Requires an input image file - Depends on pywal, wpg, swaync, pywalfox, and spicetify EOF exit 0 } validate_image() { local file="$1" local mime_type [[ -f "$file" ]] || die "File '$file' not found." mime_type=$(file --mime-type -b "$file") local allowed_types=( "image/jpeg" "image/png" "image/gif" "image/bmp" "image/webp" "image/tiff" "image/x-icon" "image/svg+xml" ) local is_image=false for type in "${allowed_types[@]}"; do if [[ "$mime_type" == "$type" ]]; then is_image=true break fi done if [[ "$is_image" == false ]]; then die "File '$file' is not a valid image. Mime type detected: $mime_type" fi } quiet_exec() { if [[ "$QUIET_MODE" == true ]]; then "$@" >/dev/null 2>&1 || return 1 else "$@" || return 1 fi } while [[ $# -gt 0 ]]; do case "$1" in -h|--help) show_help ;; -q|--quiet) QUIET_MODE=true shift ;; -n) SKIP_INITRAMFS=true shift ;; -nn) SKIP_VCONSOLE=true shift ;; *) break ;; esac done log() { if [[ "$QUIET_MODE" == false ]]; then logger -i -t "$SCRIPT" "$*" fi } die() { logger -i -t "$SCRIPT" ":Error:" "$*" exit 1 } [[ $# -eq 1 ]] || die "Usage: $0 [-h] [-q] [-n] [-nn] " IMAGE="$1" validate_image "$IMAGE" quiet_exec wal -i "$IMAGE" -n || die "Pywal update failed" quiet_exec wpg -a "$(echo "$IMAGE")" || die "Pywal adding failed." quiet_exec wpg -s "$(basename "$IMAGE")" || die "Pywal update failed." quiet_exec ln -sf "$(realpath "$IMAGE")" "$WALLPAPER" # quiet_exec eww reload # quiet_exec swaync-client -R # quiet_exec killall swaync quiet_exec pywalfox update quiet_exec spicetify apply # quiet_exec swaync-client -rs notify-send "New theme applied!" if [[ "$SKIP_VCONSOLE" == false ]]; then if [[ "$QUIET_MODE" == false ]]; then read -rp "Update vconsole.conf? (y/N): " VCONSOLE else VCONSOLE="y" fi if [[ "${VCONSOLE,,}" =~ ^y(es)?$ ]]; then [[ -f "$VCONSOLE_UPDATE" ]] || die "Vconsole update script not found" log "Running vconsole-colors update script..." quiet_exec sudo bash "$VCONSOLE_UPDATE" if [[ "$SKIP_INITRAMFS" == false ]]; then if [[ "$QUIET_MODE" == false ]]; then read -rp "Regenerate initramfs? Colors won't apply until it is. (y/N): " INITRAMFS else INITRAMFS="y" fi if [[ "${INITRAMFS,,}" =~ ^y(es)?$ ]]; then log "Regenerating initramfs from theme swap..." quiet_exec sudo mkinitcpio -P else log "Not regenerating initramfs. New colors won't apply until it has been." fi fi else log "Skipping vconsole.conf update for new theme." fi fi exit 0