#!/bin/sh

set -e

die() {
  echo "$@" >&2
  exit 1
}

matches=$(mktemp)
cleanup() {
  rm -f "${matches}"
}
trap cleanup EXIT

cmd=ack
if command -v ag >/dev/null; then
  cmd=ag
fi
if command -v rg >/dev/null; then
  cmd=rg
fi

${cmd} --column "$@" >"${matches}" || die "No matches found"

${EDITOR:-vi} +:cope -q "${matches}"
