#!/usr/bin/env bash # Originally created by - https://github.com/gh0stzk # Check if xdpyinfo and imagemagick are installed if ! command -v xdpyinfo > /dev/null 2>&1; then dunstify "Missing package" "Please install the xorg-xdpyinfo package to continue" -u critical exit 1 elif ! command -v convert > /dev/null 2>&1; then dunstify "Missing package" "Please install the imagemagick package to continue" -u critical exit 1 fi # Set some variables wall_dir="$(xdg-user-dir PICTURES)/wallpapers" cacheDir="${HOME}/.cache/wallselector" rofi_command="rofi -dmenu -theme ${HOME}/.config/rofi/wallselector.rasi -theme-str ${rofi_override}" monitor_res=$(xdpyinfo | grep dimensions | awk '{print $2}' | cut -d 'x' -f1) monitor_scale=$(xdpyinfo | grep -oP "resolution:.*" | awk '{print $2}' | cut -d 'x' -f1) monitor_res=$(( monitor_res * 17 / monitor_scale )) rofi_override="element-icon{size:${monitor_res}px;border-radius:0px;}" # Create cache dir if not exists if [ ! -d "${cacheDir}" ] ; then mkdir -p "${cacheDir}" fi # Convert images in directory and save to cache dir for image in "$wall_dir"/*.{jpg,jpeg,png,webp}; do if [ -f "$image" ]; then file_name=$(basename "$image") if [ ! -f "${cacheDir}/${file_name}" ] ; then convert -strip "$image" -thumbnail 500x500^ -gravity center -extent 500x500 "${cacheDir}/${file_name}" fi fi done # Launch rofi wall_selection=$(find "${wall_dir}" -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.webp" \) -exec basename {} \; | sort | while read -r A ; do echo -en "$A\x00icon\x1f""${cacheDir}"/"$A\n" ; done | $rofi_command) # Set wallpaper [[ -n "$wall_selection" ]] || exit 1 feh --no-fehbg --bg-fill "${wall_dir}"/"${wall_selection}" exit 0