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

View file

@ -297,6 +297,13 @@ nnoremap te :execute ':tree! | echo ":tree"'<cr>
nnoremap tt t nnoremap tt t
nnoremap ti :toggleicons<cr> nnoremap ti :toggleicons<cr>
" fzf movements
nnoremap <space>f :fzf<cr>
nnoremap <space>F :fzfhome<cr>
nnoremap <space>c :fzfcd<cr>
nnoremap <space>C :fzfcdhome<cr>
nnoremap <space>w :grep<space>
" external commands " external commands
" extract currently selected file(s) " extract currently selected file(s)
noremap ,xx :!atool -x %f<cr> noremap ,xx :!atool -x %f<cr>
@ -309,13 +316,6 @@ noremap ,xz :!atool -a %c:r.zip %f<cr>
" combine selected PDFs into single one (named output.pdf) " combine selected PDFs into single one (named output.pdf)
noremap ,pc :!pdftk %f cat output output.pdf noremap ,pc :!pdftk %f cat output output.pdf
" fzf movements
nnoremap <space>f :fzf<cr>
nnoremap <space>F :fzfhome<cr>
nnoremap <space>c :fzfcd<cr>
nnoremap <space>C :fzfcdhome<cr>
nnoremap <space>w :grep<space>
" preview thumbnails of current folder " preview thumbnails of current folder
" select thumbnails with m/M in nsxiv " select thumbnails with m/M in nsxiv
" to generate a filtered view on them " to generate a filtered view on them
@ -650,3 +650,12 @@ filetype * open
" vifm --server-name "$VIFM_SERVER_NAME" --remote +"cd '$PWD'" " vifm --server-name "$VIFM_SERVER_NAME" --remote +"cd '$PWD'"
" "
" let $VIFM_SERVER_NAME = v:servername " let $VIFM_SERVER_NAME = v:servername
command! cmpinternal vifmdiff %a %S
command! cmp : if expand('%%c') == expand('%%f')
\ | echo expand('Comparing %%"c and %%"C:t ...')
\ | cmpinternal %c %C
\ | else
\ | echo expand('Comparing files: %%"f ...')
\ | cmpinternal %f
\ | endif