#!/usr/bin/env bash

# Description: Show diff of 2 directories or multiple files in vimdiff
#
# Shell: Bash
# Author: Arun Prakash Jana

selection=~/.config/nnn/.selection

if [ -s $selection ]; then
    arr=$(cat $selection | tr '\0' '\n')
    { read -r f1; read -r f2; } <<< "$arr"

    if [ -z "$f2" ]; then
        exit
    fi

    if [ -d "$f1" ] && [ -d "$f2" ]; then
        vimdiff <(cd "$f1" && find | sort) <(cd "$f2" && find | sort)
    else
        cat $selection | xargs -0 -o vimdiff

        # For GNU xargs (note: ignoreme takes up $0)
        # cat $selection | xargs -0 bash -c '</dev/tty vimdiff "$@"' ignoreme
    fi
fi