#!/bin/sh # bpedit.sh, fstd 2018 # Dependencies (package names are for Debian) # - zlib-flate (package 'qpdf') # (for de/compression) # # - xsel (package 'xsel') # (for reading and writing the Xorg clipboard) # # - jq (package 'jq') # (for prettifying the json) # # - base64 (package 'coreutils') # (for decoding the blueprint) # # - $editor # (any will do, set your favorite below) # Usage: # 1. (Ingame) copy blueprint string # 2. ./bpedit.sh # 3. ($editor launches (see below), edit the blueprint then save+quit) # 4. (Ingame) import blueprint string # Set this to your preferred text editor editor='vim' # Check prerequisites check_installed() { if ! command -v "$1" >/dev/null 2>&1; then echo "Couldn't find the program '$1'." >&2 [ -n "$2" ] && echo "Please install the package '$2'." >&2 exit 1 fi } check_installed 'zlib-flate' 'qpdf' check_installed 'xsel' 'xsel' check_installed 'jq' 'jq' check_installed 'base64' check_installed "$editor" bp="$(mktemp /tmp/bpedit.sh.XXXXXXXXXX)" trap "rm '$bp'" EXIT trap 'exit 1' INT HUP QUIT TERM # Required blueprint format version is 0 if ! [ "x$(xsel -ob | head -n1 | cut -b1)" = 'x0' ]; then echo "Unexpected blueprint version (or bad copy, check ">&2 echo "whether 'xsel -ob' actually outputs the blueprint)" >&2 exit 1 fi # Decode, edit, encode xsel -ob | sed '1s/^.//' | base64 -d | zlib-flate -uncompress | jq . >"$bp" $editor "$bp" zlib-flate -compress <"$bp" | base64 | sed '1s/^/0/' | xsel -ib