Skip to content

Instantly share code, notes, and snippets.

@Rami-Sabbagh
Created May 22, 2017 18:14
Show Gist options
  • Save Rami-Sabbagh/ab5eb7fc4c42f9084fedcd365e9c686f to your computer and use it in GitHub Desktop.
Save Rami-Sabbagh/ab5eb7fc4c42f9084fedcd365e9c686f to your computer and use it in GitHub Desktop.
ZeroBraneStudio Verbose File Backup Saving Plugin
return {
name = "Verbose Saving",
description = "Verbose File Saving, saves a copy of each file on save in a spereate directory with data and time appended to the file name.",
author = "Rami Sabbagh",
version = 1.0,
splitFilePath = function(path)
local p,n,e = path:match("(.-)([^\\/]-%.?([^%.\\/]*))$")
n = n:sub(0,-(e:len()+2))
return p,n,e
end,
onRegister = function(self)
self.loc = ide:GetConfig().verbose_folder
if not self.loc then
error("Must set 'verbos_folder' in ZBS config inorder for verbose file saving plugin to work !")
end
end,
onUnRegister = function(self)
self.loc = nil
end,
onEditorSave = function(self,editor)
if not self.loc then return end
local filename = ide:GetDocument(editor):GetFilePath()
filename = filename:gsub("\\","/")
local path, name, extension = self.splitFilePath(filename)
local data = editor:GetText()
local time = os.date("%Y_%m_%d - %H.%M.%S",os.time())
local savename = name.." - "..time.."."..extension
local file, err = io.open(self.loc..savename,"wb")
if not file then
error(err)
else
file:write(data)
file:flush()
file:close()
end
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment