config

Personal configuration.
git clone git://code.dwrz.net/config
Log | Files | Refs

map-bg (1569B)


      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 if [[ -z "$1" ]]; then
     13   tiles="arcgis-worldimagery"
     14 fi
     15 
     16 # If no coordinates were provided, take them from the password store.
     17 if [[ -z "$2" ]]; then
     18     dir="${PASSWORD_STORE_DIR}/coordinates"
     19     locations="$(find "${dir}" -mindepth 1 -exec basename -- {} .gpg \;)"
     20     location="$(echo "${locations}" | shuf -n 1)"
     21     coordinates="$(pass coordinates/"${location}")"
     22 fi
     23 
     24 # If no zoom was provided, use a number between 8 and 18, inclusive.
     25 if [[ -z "$3" ]]; then
     26   zoom="$(shuf -i 13-18 -n 1)"
     27 fi
     28 
     29 # Create the map and store it in the maps directory.
     30 # If we fail, use an existing map.
     31 map_dir="${HOME}/.cache/maps/${width}x${height}"
     32 mkdir -p "${map_dir}"
     33 
     34 # Use a cached map, if one exists.
     35 if [[ -f "${map_dir}/${tiles}-${coordinates}-${zoom}.png" ]]; then
     36   feh --bg-fill --no-fehbg "${map_dir}/${tiles}-${coordinates}-${zoom}.png"
     37   exit 0
     38 fi
     39 
     40 # Otherwise, attempt to create a static map.
     41 # If we fail, use a random map from the cache.
     42 create-static-map \
     43   --width "${width}" --height "${height}" \
     44   --center="${coordinates}" --zoom "${zoom}" \
     45   --type "${tiles}" \
     46   --output "${map_dir}/${tiles}-${coordinates}-${zoom}.png" \
     47     && \
     48   feh --bg-fill --no-fehbg "${map_dir}/${tiles}-${coordinates}-${zoom}.png"
     49 if [[ "$?" -ne 0 ]]; then
     50   feh --bg-fill --no-fehbg --randomize "${map_dir}/"*
     51 fi