Advertisement
guitarplayer616

GitPaste lite

Jan 12th, 2017
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.19 KB | None | 0 0
  1. --fs.open("gitpaste","w").write(http.post("http://pastebin.com/raw/P39qvr3j").readAll())
  2. --Usage: gitpaste [get/run] [address] [filename]
  3.  
  4. local tArgs = {...}
  5.  
  6. function get(name,address)
  7.     local response = nil
  8.     local tmp = fs.open(name,"w")
  9.     local function setColor(color)
  10.         if term.isColor() then
  11.             term.setTextColor(color)
  12.         end
  13.     end
  14.     setColor(colors.yellow)
  15.     if address:sub(1,4) == "http" then
  16.         write("Connecting to Github.com... ")
  17.         response = http.get(address)
  18.     else
  19.         write("Connecting to Pastebin.com... ")
  20.         response = http.get("http://pastebin.com/raw/"..tostring(address))
  21.     end
  22.     if response then
  23.         setColor(colors.green)
  24.         print("Success")
  25.         tmp.write( response.readAll() )
  26.         tmp.close()
  27.         setColor(colors.white)
  28.         return true
  29.     else
  30.         setColor(colors.red)
  31.         print("Failed")
  32.         setColor(colors.white)
  33.         return false
  34.     end
  35. end
  36.  
  37. local bRespose = nil
  38. if tArgs[1] == "get" then
  39.     get(tArgs[3], tArgs[2])
  40. elseif tArgs[1] == "run" then
  41.     bResponse = get("tmp",tArgs[2])
  42.     if bResponse then
  43.         shell.run("tmp",table.concat(tArgs,", ",3) )
  44.         fs.delete("tmp")
  45.     end
  46. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement