#meta
This library adds a basic git synchronization functionality to SilverBullet. It should be considered a successor to silverbullet-git implemented in Space Lua.
The following commands are implemented:
${widgets.commandButton("Git: Sync")}
- Adds all files in your folder to git
- Commits them with the default "Snapshot" commit message
git pulls changes from the remote servergit pushes changes to the remote server
${widgets.commandButton("Git: Commit")}
- Asks you for a commit message
- Commits
config.set("git", {
autoSync = 5
})-- priority: 100
config.define("git", {
type = "object",
properties = {
autoSync = schema.number()
}
})
git = {}
function git.commit(message)
message = message or "Snapshot"
print "Comitting..."
local ok, message = pcall(function()
shell.run("git", {"add", "./*"})
shell.run("git", {"commit", "-a", "-m", message})
end)
if not ok then
print("Git commit failed: " .. message)
end
end
function git.sync()
git.commit()
print "Pulling..."
shell.run("git", {"pull"})
print "Pushing..."
shell.run("git", {"push"})
end
command.define {
name = "Git: Commit",
run = function()
local message = editor.prompt "Commit message:"
git.commit(message)
end
}
command.define {
name = "Git: Sync",
run = function()
git.sync()
editor.flashNotification "Done!"
end
}
-- priority: -1
local autoSync = config.get("git.autoSync")
if autoSync then
print("Enabling git auto sync every " .. autoSync .. " minutes")
local lastSync = 0
event.listen {
name = "cron:secondPassed",
run = function()
print "Activating timer"
local now = os.time()
if (now - lastSync)/60 >= autoSync then
lastSync = now
git.sync()
end
end
}
end
How to use this git.md?
It seems to be different from the installation method of https://github.com/silverbulletmd/silverbullet-git/blob/main/git.plug.js.
I can't put the above git.md under the 'real' Library/ even if I modify the name of the page to Library/git.
I see that almost all other #meta objects are placed under Library/std/ so that these objects can be interpreted as auto-executed scripts?
A single normal git.md in SB_space cannot generate the expected git commands.
PS: I am a new SB 2.0.0 crew :)