unixorn/tumult.plugin.zsh

View on GitHub
bin/clean-xml-clip

Summary

Maintainability
Test Coverage
#!/usr/bin/env bash
#
# Clean up the XML in the clipboard
#
# Copyright 2017, Joe Block <jpb@unixorn.net>

set -o pipefail

if [[ "$(uname -s)" != 'Darwin' ]]; then
  echo 'Sorry, this script only works on macOS'
  exit 1
fi

function has() {
  # Check if a command is in $PATH
  which "$@" > /dev/null 2>&1
}

if ! has tidy; then
  echo 'tidy not found in $PATH!'
  exit 13
fi

pbpaste | tidy -xml -wrap 0 | pbcopy
exit $?