#!/bin/sh
#
# git-vdiff - custom git-diff - substitute '/dev/null' usage with '/dev/zero'
# use of '/dev/null' results in neovim read errors when run on macos

empty_file=$(mktemp)
# ensure temporary file cleanup on exit, including abnormal termination.
trap 'rm -f "$empty_file"' EXIT

#if [ "$1" = "/dev/null" ]; then
#  nvim -d /dev/zero "$2"
#elif [ "$2" = "/dev/null" ]; then
#  nvim -d "$1" /dev/zero
#else
#  nvim -d "$1" "$2"
#fi

# custom git diff command
# this will substitute '/dev/null' usage with '$empty_file'
if [ "$1" = "/dev/null" ]; then
  NVIM_GIT_DIFF=1 nvim -d "${empty_file}" "$2"
elif [ "$2" = "/dev/null" ]; then
  NVIM_GIT_DIFF=1 nvim -d "$1" "${empty_file}"
else
  NVIM_GIT_DIFF=1 nvim -d "$1" "$2"
fi
