Skip to content

Latest commit

 

History

History
15 lines (11 loc) · 1 KB

Deletes_orphan_vim_undo_files.md

File metadata and controls

15 lines (11 loc) · 1 KB

Deletes orphan vim undo files

Command:

$ find . -type f -iname '*.un~' | while read UNDOFILE ; do FILE=$( echo "$UNDOFILE" | sed -r -e 's/.un~$//' -e 's&/\.([^/]*)&/\1&' ) ; [[ -e "$FILE" ]] || rm "$UNDOFILE" ; done

Explanation:

Explanation find -type f -iname '.un~' finds every vim undo file and outputs the path to each on a separate line. At the beginning of the while loop, each of these lines is assigned in to the variable $UNDOFILE with while read UNDOFILE, and in the body of the while loop, the file each undo-file should be tracking is calculated and assigned to $FILE with FILE=$( echo "$UNDOFILE" | sed -r -e 's/.un~$//' -e 's&/.([^/])&/\1&' ). If $FILE doesn't exist [[ -e "$FILE" ]] the undo-file is removed rm "$UNDOFILE".

Limitations:

Limitations I'm not sure whether sed in every flavour of UNIX allows the -r flag. That flag can be removed, though, as long as the parentheses in -e 's&/.([^/]*)&/\1&' are escaped (but I think the way it stands the one-liner is more readable).