1
1
mirror of https://github.com/mawww/kakoune.git synced 2024-12-25 20:41:49 +03:00

autorestore.kak: more tweaks, a WIP version was pushed by error

This commit is contained in:
Maxime Coste 2016-10-07 08:57:45 +01:00
parent f904402486
commit d89959dfa8

View File

@ -4,17 +4,17 @@ decl bool autorestore_purge_restored true
## Insert the content of the backup file into the current buffer, if a suitable one is found
def autorestore-restore-buffer -docstring "Restore the backup for the current file if it exists" %{
%sh{
buffer_basename="${kak_bufname##*/}"
buffer_dirname=$(dirname "${kak_bufname}")
test ! -f "${kak_buffile}" && exit
test ! -f "${kak_bufname}" && exit
buffer_basename=$(basename "${kak_buffile}")
buffer_dirname=$(dirname "${kak_buffile}")
## Find the name of the latest backup created for the buffer that was open
## The backup file has to have been last modified more recently than the file we are editing
## Other backups are removed
backup_path=$(find "${buffer_dirname}" -maxdepth 1 -type f -readable -name "\.${buffer_basename}\.kak\.*" \
\( \( -newer "${kak_bufname}" -printf '%A@/%p\n' \) -o \( -delete \) \) 2>/dev/null |
sort -n -t. -k1 | sed -nr 's/^[^\/]+\///;$p')
\( \( -newer "${kak_buffile}" -printf '%A@/%p\n' \) -o \( -delete \) \) 2>/dev/null |
sort -n -t. -k1 | sed 's/^[^\/]\+\///')
if [ -z "${backup_path}" ]; then
exit
@ -29,7 +29,7 @@ def autorestore-restore-buffer -docstring "Restore the backup for the current fi
## the current buffer has been saved
## If the autorestore_purge_restored option has been unset right after the
## buffer was restored, do not remove the backup
hook -group autorestore global BufWritePost (.+/)?${kak_bufname} %{
hook -group autorestore buffer BufWritePost '${kak_buffile}' %{
nop %sh{
if [ \"\${kak_opt_autorestore_purge_restored}\" = true ]; then
rm -f '${backup_path}'
@ -43,10 +43,10 @@ def autorestore-restore-buffer -docstring "Restore the backup for the current fi
## Remove all the backups that have been created for the current buffer
def autorestore-purge-backups -docstring "Remove all the backups of the current buffer" %{
nop %sh{
buffer_basename="${kak_bufname##*/}"
buffer_dirname=$(dirname "${kak_bufname}")
test ! -f "${kak_buffile}" && exit
test ! -f "${kak_bufname}" && exit
buffer_basename=$(basename "${kak_bufname}")
buffer_dirname=$(dirname "${kak_bufname}")
find "${buffer_dirname}" -maxdepth 1 -type f -readable -name "\.${buffer_basename}\.kak\.*" -delete 2>/dev/null
}
@ -58,4 +58,4 @@ def autorestore-disable -docstring "Disable automatic backup recovering" %{
rmhooks global autorestore
}
hook -group autorestore global BufCreate .* %{ autorestore-restore-buffer }
hook -group autorestore global BufOpen .* %{ autorestore-restore-buffer }