diff options
| author | 2019-06-20 18:36:07 +0530 | |
|---|---|---|
| committer | 2019-06-20 18:36:07 +0530 | |
| commit | bccc2a092146fed0435dd3339514c863196b122a (patch) | |
| tree | 0101e6e6fd5568fc9507726046065cfdff19d829 /plugins/ndiff | |
| parent | a4c38d85477ff889b2aa863e2a5b18c72dd266fb (diff) | |
| parent | 2dc3da62a2fe8672393c20ceeb1792fb0560f333 (diff) | |
| download | nnn-bccc2a092146fed0435dd3339514c863196b122a.tar.gz | |
Merge pull request #286 from ath3/plugin-md5sum
Added md5sum plugin
Diffstat (limited to 'plugins/ndiff')
| -rwxr-xr-x | plugins/ndiff | 32 |
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 |