map-bg (1588B)
1 #!/usr/bin/env bash 2 3 dimensions="$(xrandr --current | grep '*' | uniq | awk '{print $1}')" 4 height="$(echo "${dimensions}" | cut -d 'x' -f2)" 5 width="$(echo "${dimensions}" | cut -d 'x' -f1)" 6 7 tiles="$1" 8 coordinates="$2" 9 zoom="$3" 10 11 # Default to satellite imagery. 12 # Options: osm arcgis-worldimagery 13 if [[ -z "$1" ]]; then 14 tiles="osm" 15 fi 16 17 # If no coordinates were provided, take them from the password store. 18 if [[ -z "$2" ]]; then 19 dir="${PASSWORD_STORE_DIR}/coordinates" 20 locations="$(find "${dir}" -mindepth 1 -exec basename -- {} .gpg \;)" 21 location="$(echo "${locations}" | shuf -n 1)" 22 coordinates="$(pass coordinates/"${location}")" 23 fi 24 25 # If no zoom was provided, use a number between 8 and 18, inclusive. 26 if [[ -z "$3" ]]; then 27 zoom="$(shuf -i 13-18 -n 1)" 28 fi 29 30 # Create the map and store it in the maps directory. 31 # If we fail, use an existing map. 32 map_dir="${HOME}/.cache/maps/${width}x${height}" 33 mkdir -p "${map_dir}" 34 35 # Use a cached map, if one exists. 36 if [[ -f "${map_dir}/${tiles}-${coordinates}-${zoom}.png" ]]; then 37 feh --bg-fill --no-fehbg "${map_dir}/${tiles}-${coordinates}-${zoom}.png" 38 exit 0 39 fi 40 41 # Otherwise, attempt to create a static map. 42 # If we fail, use a random map from the cache. 43 create-static-map \ 44 --width "${width}" --height "${height}" \ 45 --center="${coordinates}" --zoom "${zoom}" \ 46 --type "${tiles}" \ 47 --output "${map_dir}/${tiles}-${coordinates}-${zoom}.png" \ 48 && \ 49 feh --bg-fill --no-fehbg "${map_dir}/${tiles}-${coordinates}-${zoom}.png" 50 if [[ "$?" -ne 0 ]]; then 51 feh --bg-fill --no-fehbg --randomize "${map_dir}/"* 52 fi