Files

tail.src
  • //
  • // Bobrossrtx
  • // Tail.gs -- Implementation of the unix tail command
  • // Prints out content of file on change
  • //
  • // Discord: bobrossrtx#1474
  • //
  • if params.len != 1 or params[0] == "--help" or params[0] == "-h" then
  • print("Usage: "+program_path.split("/")[-1]+" <filename>")
  • exit(1)
  • end if
  • inputFile = params[0]
  • ReadFile = function(filename)
  • content = ""
  • while true
  • file = get_shell.host_computer.File(filename)
  • if file == null then
  • print("File not found: "+filename)
  • exit(1)
  • end if
  • currContent = file.get_content
  • if currContent == content then
  • wait(1)
  • continue
  • else if currContent == null then
  • clear_screen
  • print("File deleted: "+filename)
  • exit(1)
  • else
  • content = currContent
  • clear_screen
  • print("File changed: "+filename)
  • print(content)
  • end if
  • end while
  • end function
  • Main = function()
  • ReadFile(inputFile)
  • Main
  • end function
  • Main