Skip to content

Instantly share code, notes, and snippets.

@uriel1998
Created February 13, 2014 22:13
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 uriel1998/8985004 to your computer and use it in GitHub Desktop.
Save uriel1998/8985004 to your computer and use it in GitHub Desktop.
Background manager, setter, tiler, mirrorer, etc - using mostly feh and imagemagick
#!/bin/bash
# Quite a bit of inspiration from https://gist.github.com/brycied00d/1190483
# I have a lot of backgrounds, and a laptop. I use xinarama, so my DISPLAY is always 0:0
# But I wanted to have one randomizer that used feh (2.9.3 is the version I have) but actually showed resolution-appropriate images.
# I also wanted to be able to select the color - "tiled", "orange", "blue", "black", "simple", "wide" (hooray for symlinks) at times.
# Uses xrandr to see if there is an HDMI monitor attached (which in my use cases always means I am rocking two monitors
#sets background
if [ "$1" == "tile" ]; then
#tiled, we don't care about splitting or how many monitors
color="tile"
#find
file=`find -P "/path/to/my/backgrounds/tiled" -mount -maxdepth 8 -type f | sort --random-sort | head -1`
export DISPLAY=:0.0;feh --bg-tile "$file"
else
if [ "$1" == "" ]; then
file=`find -H /path/to/my/backgrounds -type f \( -name "*.jpg" -or -name "*.png" -or -name "*.jpeg" \) | grep -v "tiled" | sort --random-sort | head -1`
else
color="$1"
file=`ls -1 /path/to/my/backgrounds/$color/* | sort --random-sort | head -1`
fi
#do we have more than one monitor?
hdmiconnected=`xrandr | grep "HDMI1 disconnected"`
hdmivalue="HDMI1 disconnected (normal left inverted right x axis y axis)"
# only one monitor
if [ "$hdmiconnected" = "$hdmivalue" ]; then
# we have one monitor
export DISPLAY=:0.0;feh --bg-fill --no-xinerama "$file"
else
#is the wallpaper wide enough to span both?
imgwidth=`identify -format "%w" "$file"`
if [ "$imgwidth" -lt "2000" ];then
#so we mirror it
cp "$file" /tmp/wallpaper-0.jpg
convert "$file" -flop /tmp/wallpaper-1.jpg
else
#we need to split wallpaper
nice -n 19 convert -crop 50%x100% +repage "$file" /tmp/wallpaper.jpg
fi
DISPLAY=:0.0 feh --bg-scale /tmp/wallpaper-0.jpg /tmp/wallpaper-1.jpg &
fi
fi
#echo "$file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment