vifm: Add simple file and folder diff command

The newly added `:cmp` command can compare the contents of either two
files or two directories.

Works in two ways: If nothing is selected, compares the currently
hovered-over object with that in the other pane.
If things are selected, compares those instead.
This commit is contained in:
Marty Oehme 2024-05-28 21:39:47 +02:00
parent 54f553f75c
commit b8cbc8bc5d
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A
2 changed files with 47 additions and 7 deletions

View file

@ -0,0 +1,31 @@
#!/bin/bash
if [ $# != 2 ] ; then
echo 'Expected exactly two arguments'
exit 1
fi
if [ -f "$1" ] && [ -f "$2" ]; then
args=
elif [ -d "$1" ] && [ -d "$2" ]; then
args='-r'
else
if [ -f "$1" ]; then
type_of_1='file'
else
type_of_1='directory'
fi
if [ -f "$2" ]; then
type_of_2='file'
else
type_of_2='directory'
fi
echo "Arguments are of different type ($type_of_1/$type_of_2)"
exit 1
fi
if diff $args "$1" "$2" > /dev/null 2>&1; then
echo 'Equal'
else
echo 'Not equal'
fi