* Chris Suter <[email protected]> [2009-10-06 20:12 -0400]:
> oops looks like i was wrong -- the .swp files are left around. the following
> should fix this:
>
> find . -name '*.swp' | \
> sed 's/\(.*\/\)\.\([^.]\+\(\.[^.]\+\)\?\)\.swp/\1\2/' | \
> while read i
> do
> cp $i $i".old"
> vim -r $i -e -c 'wq'
> if [[ `diff $i $i".old" | wc -l` -eq 0 ]]
> then
> mv $i".old" $i
> rm `dirname $i`/"."`basename $i`".swp"
> fi
> done
>
> the added rm command just reconstructs the name of the swp file from the
> name of the original using backticks to pull out the path and the filename.
> This is now a big ugly hack which could probably be cleaned up quite a bit,
> but ought to work anyway.
Sorry, couldn't help it since shell scripting is a hobby for me... :->
#! /bin/sh
find . -name '*.swp' -type f -exec sh -c '
swap=$1
dir=${swap%/*} # dirname
tmp=${swap##*/.} # trim leading path and dot
file=${dir}/${tmp%.swp} # original file, trim .swp
ofile=$file.tmp$$ # temporary "old file"
cp "$file" "$ofile"
vim -r "$file" -e -c wq
if cmp -s "$file" "$ofile"
then
mv "$ofile" "$file"
rm -f "$swap"
fi' sh {} \;
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---