On Oct 6, 7:52 pm, Yang Zhang <[email protected]> wrote:
< snip >
> Is there a way (or are there any tools) to automate this highly manual
> recovery process? I.e., given a set of .swp files, for each one
> compare the recovered file with the original and discard the swp if
> it's useless (leaving in place the ones that could not be
> automatically pruned out)?
I asked myself the same question some time ago. Then, I came across
bash script (this makes it more usefull in UNIX-like OSes) which I
modified only slightly. Unfortunately, I can't recall where I got it
from to give the author due credit. It was posted somewhere, so I take
the liberty to re-post it here (with my tiny modification). Basically,
you run it from the directory where the .swp files are and it will
compare the .swp with the original file and present you a vimdiff
window if the differ. Test it before production use to get familiar
with it.
jorge
cleanswap:
#!/bin/bash
TMPDIR=$(mktemp -d) || exit 1
RECTXT="$TMPDIR/vim.recovery.$USER.txt"
RECFN="$TMPDIR/vim.recovery.$USER.fn"
trap 'rm -f "$RECTXT" "$RECFN"; rmdir "$TMPDIR"' 0 1 2 3 15
#for q in ~/.vim/swap/.*sw? ~/.vim/swap/*; do
for q in ./.*sw?; do
[[ -f $q ]] || continue
rm -f "$RECTXT" "$RECFN"
vim -X -r "$q" \
-c "w! $RECTXT" \
-c "let fn=expand('%')" \
-c "new $RECFN" \
-c "exec setline( 1, fn )" \
-c w\! \
-c "qa"
if [[ ! -f $RECFN ]]; then
echo "nothing to recover from $q"
rm -f "$q"
continue
fi
CRNT="$(cat $RECFN)"
if diff --strip-trailing-cr --brief "$CRNT" "$RECTXT"; then
echo "removing redundant $q"
echo " for $CRNT"
rm -f "$q"
else
echo $q contains changes
vim -n -d "$CRNT" "$RECTXT"
rm -i "$q" || exit
fi
done
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---