Skip to content

Instantly share code, notes, and snippets.

@Rami-Sabbagh
Last active May 22, 2017 19:30
Show Gist options
  • Save Rami-Sabbagh/643d808eb2aeb3995d09354d7a06165d to your computer and use it in GitHub Desktop.
Save Rami-Sabbagh/643d808eb2aeb3995d09354d7a06165d to your computer and use it in GitHub Desktop.
ZeroBraneStudio Verbose File Backup Saving Plugin
-- You have to add this to zbs user.lua configuration file
verbose_folder = "C:/Users/Your_User/Documents/ZBS Backup/" --For example, you must use / , and be sure that the path ends with /
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.2,
splitFilePath = function(path) return path:match("(.-)([^\\/]-%.?([^%.\\/]*))$") 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 = time.." - "..name
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