aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-06-03 18:40:29 +0530
committerGravatar Arun Prakash Jana <engineerarun@gmail.com>2019-06-03 20:29:37 +0530
commitaa6013378f2152521ff5b4eaeef3fdcc0c192334 (patch)
tree1b4ba459f9c63625911dfb1e7a4301de36cf4343
parentedf587a48f9dfdee92399b713d5ae0e39789bf70 (diff)
downloadnnn-aa6013378f2152521ff5b4eaeef3fdcc0c192334.tar.gz
Make diff work with filenames with spaces
-rwxr-xr-xplugins/ndiff22
1 files changed, 17 insertions, 5 deletions
diff --git a/plugins/ndiff b/plugins/ndiff
index 46e829a..e76b151 100755
--- a/plugins/ndiff
+++ b/plugins/ndiff
@@ -5,10 +5,22 @@
# Shell: Bash
# Author: Arun Prakash Jana
-arr=($(cat ~/.config/nnn/.selection | tr '\0' '\n'))
+selection=~/.config/nnn/.selection
-if [ -d "${arr[0]}" ] && [ -d "${arr[1]}" ]; then
- vimdiff <(cd ${arr[0]} && find | sort) <(cd ${arr[1]} && find | sort)
-else
- vimdiff "${arr[@]}"
+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