diff options
author | Arun Prakash Jana <engineerarun@gmail.com> | 2019-11-22 17:51:13 +0530 |
---|---|---|
committer | Arun Prakash Jana <engineerarun@gmail.com> | 2019-11-22 17:51:13 +0530 |
commit | 594d645e259083b217518ef0507edfe5395711af (patch) | |
tree | 531fcf59d50287011797fd3179258379b0376622 /plugins/diffs | |
parent | 085bda03305ffd5cb502743a06ac6b2513b7234e (diff) | |
download | nnn-594d645e259083b217518ef0507edfe5395711af.tar.gz |
Rename plugins, group related ones
Diffstat (limited to 'plugins/diffs')
-rwxr-xr-x | plugins/diffs | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/plugins/diffs b/plugins/diffs new file mode 100755 index 0000000..3680627 --- /dev/null +++ b/plugins/diffs @@ -0,0 +1,35 @@ +#!/usr/bin/env sh + +# Description: Show diff of 2 directories or multiple files in vimdiff +# +# Note: vim may show the warning: 'Vim: Warning: Input is not from a terminal' +# press 'Enter' to ignore and proceed. +# +# Shell: POSIX compliant +# Authors: Arun Prakash Jana, ath3 + +selection=${XDG_CONFIG_HOME:-$HOME/.config}/nnn/.selection + +if [ -s "$selection" ]; then + 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 + # If xargs supports the -o option, use it to get rid of: + # Vim: Warning: Input is not from a terminal + # xargs -0 -o vimdiff < $selection + + xargs -0 vimdiff +0 < "$selection" + fi + else + echo "needs at least 2 files or directories selected for comparison" + fi +fi |