[Assorted-commits] SF.net SVN: assorted:[1828] shell-tools/trunk
Brought to you by:
yangzhang
From: <yan...@us...> - 2012-03-15 22:17:57
|
Revision: 1828 http://assorted.svn.sourceforge.net/assorted/?rev=1828&view=rev Author: yangzhang Date: 2012-03-15 22:17:51 +0000 (Thu, 15 Mar 2012) Log Message: ----------- Add clean-swp Modified Paths: -------------- shell-tools/trunk/README Added Paths: ----------- shell-tools/trunk/src/clean-swp.bash Modified: shell-tools/trunk/README =================================================================== --- shell-tools/trunk/README 2012-02-10 09:05:45 UTC (rev 1827) +++ shell-tools/trunk/README 2012-03-15 22:17:51 UTC (rev 1828) @@ -52,6 +52,9 @@ from a directory tree. implementation, [HSH] +`clean-swp` Clean up vim swap files, removing any redundant bash, vim + files and vimdiffing the rest. + `clobber- Only replace an existing file if the contents Python if-diff` actually changed. Useful in Makefiles. Added: shell-tools/trunk/src/clean-swp.bash =================================================================== --- shell-tools/trunk/src/clean-swp.bash (rev 0) +++ shell-tools/trunk/src/clean-swp.bash 2012-03-15 22:17:51 UTC (rev 1828) @@ -0,0 +1,43 @@ +#!/usr/bin/env bash + +# <http://stackoverflow.com/a/5826793/43118> + +IFS=$'\n' + +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 "$@"; do + echo $q + [[ -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 [ "$CRNT" = "$RECTXT" ]; then + echo "Can't find original file. Press enter to open vim so you can save the file. The swap file will be deleted afterward!" + read + vim "$CRNT" + rm -f "$q" + else if diff --strip-trailing-cr --brief "$CRNT" "$RECTXT"; then + echo "Removing redundant $q" + echo " for $CRNT" + rm -f "$q" + else + echo $q contains changes, or there may be no original saved file + vim -n -d "$CRNT" "$RECTXT" + rm -i "$q" || exit + fi + fi +done Property changes on: shell-tools/trunk/src/clean-swp.bash ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |