Created
March 2, 2020 09:37
-
-
Save grational/57f02243f2b2d77a0c305a14817004fe to your computer and use it in GitHub Desktop.
vim-recover: recover all the vim orphan swap files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# vim-recover: recover all the orphan swap files | |
# @version: 0.5b | |
# @require: set directory=~/.config/nvim/swap_files// | |
# @author: Giuseppe Ricupero | |
# @e-mail: [email protected] | |
set -euo pipefail | |
IFS=$'\n\t' | |
vim_flavour=/usr/bin/vim | |
# vim_flavour=nvim | |
swap_dir="${HOME}/.config/nvim/swap_files" | |
process() { | |
# avoid currently opened swaps | |
lsof "$1" &>/dev/null && return 1 | |
# proceed | |
swap="${1}" | |
file="${1##*/}"; file="${file//%//}"; file="${file%.sw?}" | |
echo "Editing ${file}" | |
sleep 1 | |
set -x | |
$vim_flavour -r "${file}" | |
set +x | |
read -p "Ok to delete swap file? " -n1 -r; echo | |
if [[ $REPLY =~ ^[Yy]$ ]]; then | |
echo "Deleting ${swap}" | |
rm "${swap}" | |
fi | |
echo "---" | |
} | |
export vim_flavour | |
export -f process | |
# edge case: swap of the home dir. You cannot exit from this! | |
rm -f "${swap_dir}/${HOME////%}.swp" | |
find "${swap_dir}" -type f -exec bash -c 'process "{}"' \; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment