3 # Description: Show diff of 2 directories or multiple files in vimdiff
6 # 1. vim may show the warning: 'Vim: Warning: Input is not from a terminal'
7 # press 'Enter' to ignore and proceed.
8 # 2. if only one file is in selection, the hovered file is considered as the
9 # second file to diff with
11 # Shell: POSIX compliant
12 # Authors: Arun Prakash Jana, ath3
14 selection=${NNN_SEL:-${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection}
16 if type nvim >/dev/null 2>&1; then
23 dir1=$(mktemp "${TMPDIR:-/tmp}"/nnn-"$(basename "$1")".XXXXXXXX)
24 dir2=$(mktemp "${TMPDIR:-/tmp}"/nnn-"$(basename "$2")".XXXXXXXX)
27 $diffcmd "$dir1" "$dir2"
31 if [ -s "$selection" ]; then
32 arr=$(tr '\0' '\n' < "$selection")
33 if [ "$(echo "$arr" | wc -l)" -gt 1 ]; then
34 f1="$(echo "$arr" | sed -n '1p')"
35 f2="$(echo "$arr" | sed -n '2p')"
36 if [ -d "$f1" ] && [ -d "$f2" ]; then
39 # If xargs supports the -o option, use it to get rid of:
40 # Vim: Warning: Input is not from a terminal
41 # xargs -0 -o vimdiff < $selection
43 eval xargs -0 "$diffcmd" < "$selection"
45 elif [ -n "$1" ]; then
46 f1="$(echo "$arr" | sed -n '1p')"
47 if [ -d "$f1" ] && [ -d "$1" ]; then
49 elif [ -f "$f1" ] && [ -f "$1" ]; then
52 echo "cannot compare file with directory"
55 echo "needs at least 2 files or directories selected for comparison"
60 if [ -p "$NNN_PIPE" ]; then
61 printf "-" > "$NNN_PIPE"