Added wallpaper selector
This commit is contained in:
44
misc/bin/wallselector
Normal file
44
misc/bin/wallselector
Normal file
@@ -0,0 +1,44 @@
|
||||
#!/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="${HOME}/pics/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
|
||||
nombre_archivo=$(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
|
Reference in New Issue
Block a user