#!/usr/bin/env bash
#
# ppjson - pretty print json
#
# usage:
#   ppjson [file path] [jq args]
#
# examples:
#   ppjson myfile.json  Pretty print the contents of a file
#   ppjson              Pretty print the contents of your clipboard
#   ppjson --indent 4   Pretty print your clipboard with 4 spaces

set -eu

file="${1:-}"

if [ -f "${file}" ]; then
  shift
  # shellcheck disable=SC2068
  jq ${@:-} <"${file}"
else
  # shellcheck disable=SC2068
  if command -v pbpaste >/dev/null 2>&1; then
    pbpaste
  else
    xcp -o
  fi | jq ${@:-}
fi
