Skip to content

Instantly share code, notes, and snippets.

@zefhemel
Created April 24, 2025 17:55
Show Gist options
  • Save zefhemel/df94468428db3fe7049612cefbb8628a to your computer and use it in GitHub Desktop.
Save zefhemel/df94468428db3fe7049612cefbb8628a to your computer and use it in GitHub Desktop.

#meta

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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment