aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/ndiff
diff options
context:
space:
mode:
authorGravatar ath3 <ha05190@protonmail.com>2019-06-20 10:45:24 +0200
committerGravatar ath3 <ha05190@protonmail.com>2019-06-20 10:45:24 +0200
commit2dc3da62a2fe8672393c20ceeb1792fb0560f333 (patch)
tree30075b6a1ac603c8d4c0548c0cbb058eb6c65718 /plugins/ndiff
parent682e810e6e893a1b8824a9eef032ff1fea9eaafc (diff)
downloadnnn-2dc3da62a2fe8672393c20ceeb1792fb0560f333.tar.gz
Refactored splitjoin and ndiff plugins, made them POSIX compliant
Diffstat (limited to 'plugins/ndiff')
-rwxr-xr-xplugins/ndiff32
1 files changed, 17 insertions, 15 deletions
diff --git a/plugins/ndiff b/plugins/ndiff
index e76b151..59193ff 100755
--- a/plugins/ndiff
+++ b/plugins/ndiff
@@ -1,26 +1,28 @@
-#!/usr/bin/env bash
+#!/usr/bin/env sh
# Description: Show diff of 2 directories or multiple files in vimdiff
#
-# Shell: Bash
+# Shell: POSIX compliant
# 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)
+ arr=$(tr '\0' '\n' < "$selection")
+ if [ "$(echo "$arr" | wc -l)" -gt 1 ]; then
+ f1="$(echo "$arr" | sed -n '1p')"
+ f2="$(echo "$arr" | sed -n '2p')"
+ if [ -d "$f1" ] && [ -d "$f2" ]; then
+ dir1=$(mktemp "${TMPDIR:-/tmp}"/nnn-$(basename "$f1").XXXXXXXX)
+ dir2=$(mktemp "${TMPDIR:-/tmp}"/nnn-$(basename "$f2").XXXXXXXX)
+ ls -A1 "$f1" > "$dir1"
+ ls -A1 "$f2" > "$dir2"
+ vimdiff "$dir1" "$dir2"
+ rm "$dir1" "$dir2"
+ else
+ cat $selection | xargs -0 vimdiff
+ fi
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
+ echo "needs at least 2 files or directories selected for comparison"
fi
fi