#!/usr/bin/env bash
set -euo pipefail

command -v jc >/dev/null || {
  echo "jc not found" >&2
  exit 127
}
command -v jq >/dev/null || {
  echo "jq not found" >&2
  exit 127
}

# If first arg looks like a jq filter flag (-f/-r or starts with '.'),
# treat it as a jq filter; otherwise default to pretty-print (.)
jq_filter='.'
if [[ ${1-} =~ ^-f$|^-r$|\..* ]]; then
  jq_filter="$1"
  shift || true
fi

# -P gives portable output (one line per FS), which makes parsing sturdier.
exec df -P "$@" | jc --df | jq "$jq_filter"
