Skip to content

Instantly share code, notes, and snippets.

@brantsch
Created October 4, 2015 08:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brantsch/c4f7c974e2aab74b8d57 to your computer and use it in GitHub Desktop.
Save brantsch/c4f7c974e2aab74b8d57 to your computer and use it in GitHub Desktop.
Wrap i3lock to randomly select an image from a folder and automatically scale it to fit your monitor resolution.
#!/bin/bash
random_wallpaper="$(find $1 -maxdepth 1 -name *.png | shuf | head -1)"
actual_size="$(identify -format %wx%h $random_wallpaper)"
target_size=$(xrandr | head -n 1 | awk -e '{OFS=""; gsub("[ ,]+","",$10); print $8,"x",$10;}')
if [[ "$actual_size" != "$target_size" ]]; then
convert "$random_wallpaper" -background black -gravity center -scale $target_size -extent $target_size png:- | i3lock -i /proc/self/fd/0
else
i3lock -t -i "$random_wallpaper"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment