diff options
Diffstat (limited to 'plugins/diffs')
| -rwxr-xr-x | plugins/diffs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/plugins/diffs b/plugins/diffs index 71f6817..ff85aa8 100755 --- a/plugins/diffs +++ b/plugins/diffs @@ -12,12 +12,18 @@ selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection +if which nvim >/dev/null 2>&1; then + diffcmd="nvim -d" +else + diffcmd="vimdiff +0" +fi + dirdiff() { dir1=$(mktemp "${TMPDIR:-/tmp}"/nnn-"$(basename "$1")".XXXXXXXX) dir2=$(mktemp "${TMPDIR:-/tmp}"/nnn-"$(basename "$2")".XXXXXXXX) ls -A1 "$1" > "$dir1" ls -A1 "$2" > "$dir2" - vimdiff "$dir1" "$dir2" + $diffcmd "$dir1" "$dir2" rm "$dir1" "$dir2" } @@ -33,14 +39,14 @@ if [ -s "$selection" ]; then # Vim: Warning: Input is not from a terminal # xargs -0 -o vimdiff < $selection - xargs -0 vimdiff +0 < "$selection" + eval xargs -0 "$diffcmd" < "$selection" fi elif ! [ -z "$1" ]; then f1="$(echo "$arr" | sed -n '1p')" if [ -d "$f1" ] && [ -d "$1" ]; then dirdiff "$f1" "$1" elif [ -f "$f1" ] && [ -f "$1" ]; then - vimdiff +0 "$f1" "$1" + $diffcmd "$f1" "$1" else echo "cannot compare file with directory" fi |