autorestore.kak: more tweaks, a WIP version was pushed by error
This commit is contained in:
parent
f904402486
commit
d89959dfa8
|
@ -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
|
## 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" %{
|
def autorestore-restore-buffer -docstring "Restore the backup for the current file if it exists" %{
|
||||||
%sh{
|
%sh{
|
||||||
buffer_basename="${kak_bufname##*/}"
|
test ! -f "${kak_buffile}" && exit
|
||||||
buffer_dirname=$(dirname "${kak_bufname}")
|
|
||||||
|
|
||||||
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
|
## 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
|
## The backup file has to have been last modified more recently than the file we are editing
|
||||||
## Other backups are removed
|
## Other backups are removed
|
||||||
backup_path=$(find "${buffer_dirname}" -maxdepth 1 -type f -readable -name "\.${buffer_basename}\.kak\.*" \
|
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 |
|
\( \( -newer "${kak_buffile}" -printf '%A@/%p\n' \) -o \( -delete \) \) 2>/dev/null |
|
||||||
sort -n -t. -k1 | sed -nr 's/^[^\/]+\///;$p')
|
sort -n -t. -k1 | sed 's/^[^\/]\+\///')
|
||||||
|
|
||||||
if [ -z "${backup_path}" ]; then
|
if [ -z "${backup_path}" ]; then
|
||||||
exit
|
exit
|
||||||
|
@ -29,7 +29,7 @@ def autorestore-restore-buffer -docstring "Restore the backup for the current fi
|
||||||
## the current buffer has been saved
|
## the current buffer has been saved
|
||||||
## If the autorestore_purge_restored option has been unset right after the
|
## If the autorestore_purge_restored option has been unset right after the
|
||||||
## buffer was restored, do not remove the backup
|
## buffer was restored, do not remove the backup
|
||||||
hook -group autorestore global BufWritePost (.+/)?${kak_bufname} %{
|
hook -group autorestore buffer BufWritePost '${kak_buffile}' %{
|
||||||
nop %sh{
|
nop %sh{
|
||||||
if [ \"\${kak_opt_autorestore_purge_restored}\" = true ]; then
|
if [ \"\${kak_opt_autorestore_purge_restored}\" = true ]; then
|
||||||
rm -f '${backup_path}'
|
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
|
## 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" %{
|
def autorestore-purge-backups -docstring "Remove all the backups of the current buffer" %{
|
||||||
nop %sh{
|
nop %sh{
|
||||||
buffer_basename="${kak_bufname##*/}"
|
test ! -f "${kak_buffile}" && exit
|
||||||
buffer_dirname=$(dirname "${kak_bufname}")
|
|
||||||
|
|
||||||
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
|
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
|
rmhooks global autorestore
|
||||||
}
|
}
|
||||||
|
|
||||||
hook -group autorestore global BufCreate .* %{ autorestore-restore-buffer }
|
hook -group autorestore global BufOpen .* %{ autorestore-restore-buffer }
|
||||||
|
|
Loading…
Reference in New Issue
Block a user