Commit d37b9a3a authored by Marco Kellershoff's avatar Marco Kellershoff 🤸

Working v1.0.0

parent 8d2d455f
......@@ -5,9 +5,20 @@ IncrementalFileBackup.nvim
A Vim/Neovim plugin to backup files incrementally before every save.
## Installation
This plugin can be installed with a varity of plugin managers, e.g.,
[vim-plug](https://github.com/junegunn/vim-plug):
```
Plug 'https://git.superevilmegaco.com/Neovim/IncrementalFileBackup.nvim'
```
## Usage
`:IncrementalFileBackupEnable` to enable file backup.
`:IncrementalFileBackupDisable` to disable file backup.
Backups are written to the `~/.IncrementalFileBackup.nvim/` directory.
......@@ -5,13 +5,40 @@ let g:loaded_IncrementalFileBackup = 1
let s:PluginName = "IncrementalFileBackup.nvim"
let s:isVerbose = 0
let s:backupDir = "~/.IncrementalFileBackup.nvim"
function! IncrementalFileBackup#Backup()
let bex = '-' . strftime("%Y%m%d-%k%M%S")
let filepath = expand('%:p')
let dirpath = expand('%:p:h')
let backupDirPath = s:backupDir . dirpath
let backupFilePath = s:backupDir . filepath . bex
let cmd = "!mkdir -p ". backupDirPath . " && cp " . filepath . " " . backupFilePath
silent execute cmd
echom "IncrementalFileBackup: Backup written to ". backupFilePath
endfunction
function! s:RegisterAutoCommandOnBufWrite(enable)
if a:enable == 1
augroup AutoIncrementalFileBackupOnBufWriteAugroup
autocmd!
autocmd! BufWritePre * :call IncrementalFileBackup#Backup()
augroup END
else
augroup AutoIncrementalFileBackupOnBufWriteAugroup
autocmd!
augroup END
endif
endfunction
function! IncrementalFileBackup#Enable()
let &bex = '-' . strftime("%Y%m%d%H%M%S") . '~'
:au BufWritePre * let &bex = '-' . strftime("%Y%b%d%X") . '~'
silent! "!mkdir -p " . s:backupDir
call s:RegisterAutoCommandOnBufWrite(1)
endfunction
function! IncrementalFileBackup#Disable()
call s:RegisterAutoCommandOnBufWrite(0)
endfunction
command! IncrementalFileBackupEnable call IncrementalFileBackup#Enable()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment