Advertisement
CoLDarkness

OpenComputers-MyGithub

Jan 19th, 2014
1,735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.13 KB | None | 0 0
  1. -- Modified pastebin @ OC for github purposes.
  2. http.get = http.request
  3. local args, options = shell.parse(...)
  4. if #args < 2 then
  5.   print("Usage: git [-f] <id> <file>")
  6.   print(" -f: Force overwriting existing files.")
  7.   print(" -k: keep line endings as-is (will convert")
  8.   print("     Windows line endings to Unix otherwise).")
  9.   return
  10. end
  11.  
  12. local m = component.modem
  13. if not m or not m.isWireless() then
  14.   print("no primary wireless modem found")
  15.   return
  16. end
  17.  
  18. if not m.isHttpEnabled() then
  19.   print("http support is not enabled")
  20.   return
  21. end
  22.  
  23. local id = args[1]
  24. local filename = shell.resolve(args[2])
  25.  
  26. if fs.exists(filename) then
  27.   if not options.f or not os.remove(filename) then
  28.     print("file already exists")
  29.     return
  30.   end
  31. end
  32.  
  33. local f, reason = io.open(filename, "w")
  34. if not f then
  35.   print("failed opening file for writing: " .. reason)
  36.   return
  37. end
  38.  
  39. local url = "https://raw2.github.com/DaVinci234/OpenComputers/master/" .. id
  40. for chunk in http.request(url) do
  41.   if not options.k then
  42.     string.gsub(chunk, "\r\n", "\n")
  43.   end
  44.   f:write(chunk)
  45. end
  46.  
  47. f:close()
  48. print("saved data to " .. filename)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement