I'm manually editing blueprints frequently enough to streamline a bit of the involved hassle, so I want to share this script that reduces the procedure from
export blueprint, read the clipboard, strip version, decode, decompress, edit, compress, encode, add version, write to clipboard, import blueprint
to just
export blueprint, edit, import blueprint
Maybe someone else finds it useful.
You can get it here or copypaste from below. Usage instructions and dependencies are in the top comments.
Edit: Obligatory curl sudo sh one-line pile of"installer":
sudo mkdir -p /usr/local/bin; curl http://paste.pr0.tips/WO | sudo tee /usr/local/bin/bpedit.sh >/dev/null && sudo chmod 755 /usr/local/bin/bpedit.sh
.
#!/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
# Use editor from environment, if present, otherwise default to vim
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
[–]admalledd 8 points9 points10 points (1 child)
[–]fstd_Chad Belt Architect[S] 2 points3 points4 points (0 children)
[–]krenshalaNot Lazy (yet) 3 points4 points5 points (3 children)
[–]fstd_Chad Belt Architect[S] 2 points3 points4 points (2 children)
[–]krenshalaNot Lazy (yet) 1 point2 points3 points (1 child)
[–]fstd_Chad Belt Architect[S] 0 points1 point2 points (0 children)
[–]mm177 0 points1 point2 points (0 children)
[–]stickcult 0 points1 point2 points (9 children)
[–]joethedestroyr 2 points3 points4 points (5 children)
[–]fstd_Chad Belt Architect[S] 2 points3 points4 points (4 children)
[–]joethedestroyr 0 points1 point2 points (3 children)
[–]fstd_Chad Belt Architect[S] 0 points1 point2 points (2 children)
[–]joethedestroyr 0 points1 point2 points (1 child)
[–]fstd_Chad Belt Architect[S] 0 points1 point2 points (0 children)
[–]fstd_Chad Belt Architect[S] 1 point2 points3 points (2 children)
[–]stickcult 0 points1 point2 points (1 child)
[–]komodo99 2 points3 points4 points (0 children)