#!/bin/sh
#
# with-delta - creates a temporary directory, copies cdiff to it as diff and
# then adds that temporary directory to the leading part of PATH.
# in effect, this causes the sub-command executed to use `delta` for diffing.
# we do this because delta doesn't seem to work always (e.g., `pass` breaks).

if ! cmd-exists delta; then
  echo "delta diff tool not installed" >&2
  exit 1
fi

dir="$(mktemp -d)"
trap 'rm -rf "$dir"' EXIT

cp "${HOME%/}/bin/cdiff" "${dir}/diff"
PATH="${dir}:${PATH}" "$@"
