set -e
cleanup() {
rm -r "$TEMPDIR"
}
die() {
echo "$1" 1>&2
cleanup
exit 1
}
DELTA="${1:-./target/release/delta} --no-gitconfig --navigate"
unset DELTA_PAGER
TEMPDIR="$(mktemp -d)"
export PAGER="$TEMPDIR/less"
cat >"$PAGER" <<-EOF
#!/bin/sh
cat
EOF
chmod 755 $PAGER
test_delta_less_hist_file_created () {
DELTA_HIST_FILE="${XDG_DATA_HOME:-$HOME/.local/share}/delta/lesshst"
rm -f ~/.lesshst "$DELTA_HIST_FILE"
[ -e "$DELTA_HIST_FILE" ] && die "Expected \"$DELTA_HIST_FILE\" not to exist"
if [[ "$OSTYPE" = darwin* ]]; then
script -q /dev/null git -c pager.log="$DELTA" log -p HEAD~2...HEAD > /dev/null
else
git -c pager.log="$DELTA" log -p HEAD~2...HEAD
fi
[ -e "$DELTA_HIST_FILE" ] || die "Expected \"$DELTA_HIST_FILE\" to exist"
}
test_delta_less_hist_file_created
export LESSHISTFILE=$TEMPDIR/delta.lesshst
test_delta_less_hist_file_created
cat >$LESSHISTFILE <<-EOF
.shell
"pwd
"ls -Al ../data/
EOF
test_delta_less_hist_file_created
cat >>$LESSHISTFILE <<-EOF
.mark
m a 1 7740 /etc/gitconfig
m b 1 4221 /etc/profile
EOF
test_delta_less_hist_file_created
cleanup