Advertisement
Guest User

startup

a guest
Jun 13th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.61 KB | None | 0 0
  1.  
  2. -- Setup paths
  3. local sPath = ".:/rom/programs"
  4. if term.isColor() then
  5.     sPath = sPath..":/rom/programs/advanced"
  6. end
  7. if turtle then
  8.     sPath = sPath..":/rom/programs/turtle"
  9. else
  10.     sPath = sPath..":/rom/programs/rednet:/rom/programs/fun"
  11.     if term.isColor() then
  12.         sPath = sPath..":/rom/programs/fun/advanced"
  13.     end
  14. end
  15. if pocket then
  16.     sPath = sPath..":/rom/programs/pocket"
  17. end
  18. if commands then
  19.     sPath = sPath..":/rom/programs/command"
  20. end
  21. if http then
  22.     sPath = sPath..":/rom/programs/http"
  23. end
  24. shell.setPath( sPath )
  25. help.setPath( "/rom/help" )
  26.  
  27. -- Setup aliases
  28. shell.setAlias( "ls", "list" )
  29. shell.setAlias( "dir", "list" )
  30. shell.setAlias( "cp", "copy" )
  31. shell.setAlias( "mv", "move" )
  32. shell.setAlias( "rm", "delete" )
  33. shell.setAlias( "clr", "clear" )
  34. shell.setAlias( "rs", "redstone" )
  35. shell.setAlias( "sh", "shell" )
  36. if term.isColor() then
  37.     shell.setAlias( "background", "bg" )
  38.     shell.setAlias( "foreground", "fg" )
  39. end
  40.  
  41. --[ kaziu687's mod autolabel
  42. if not os.getComputerLabel() then
  43.   os.setComputerLabel("ID: "..os.getComputerID())
  44.   print("Computer has named as: "..os.getComputerLabel())
  45.   if turtle then
  46.     print("FakePlayer's name: [CC_Turtle_"..os.getComputerID().."]")
  47.   end
  48. end
  49. --] end
  50.  
  51. --[ kaziu687's mod remove world interacts (remaining, FakePlayer introduced)
  52.  
  53. if turtle then
  54.   function turtle.attack()
  55.     return false
  56.   end
  57.   function turtle.attackUp()
  58.     return false
  59.   end
  60.   function turtle.attackDown()
  61.     return false
  62.   end
  63. end
  64. --] end
  65.  
  66. -- Setup completion functions
  67. local function completeMultipleChoice( sText, tOptions, bAddSpaces )
  68.     local tResults = {}
  69.     for n=1,#tOptions do
  70.         local sOption = tOptions[n]
  71.         if #sOption + (bAddSpaces and 1 or 0) > #sText and string.sub( sOption, 1, #sText ) == sText then
  72.             local sResult = string.sub( sOption, #sText + 1 )
  73.             if bAddSpaces then
  74.                 table.insert( tResults, sResult .. " " )
  75.             else
  76.                 table.insert( tResults, sResult )
  77.             end
  78.         end
  79.     end
  80.     return tResults
  81. end
  82. local function completePeripheralName( sText, bAddSpaces )
  83.     return completeMultipleChoice( sText, peripheral.getNames(), bAddSpaces )
  84. end
  85. local tRedstoneSides = redstone.getSides()
  86. local function completeSide( sText, bAddSpaces )
  87.     return completeMultipleChoice( sText, tRedstoneSides, bAddSpaces )
  88. end
  89. local function completeFile( shell, nIndex, sText, tPreviousText )
  90.     if nIndex == 1 then
  91.         return fs.complete( sText, shell.dir(), true, false )
  92.     end
  93. end
  94. local function completeDir( shell, nIndex, sText, tPreviousText )
  95.     if nIndex == 1 then
  96.         return fs.complete( sText, shell.dir(), false, true )
  97.     end
  98. end
  99. local function completeEither( shell, nIndex, sText, tPreviousText )
  100.     if nIndex == 1 then
  101.         return fs.complete( sText, shell.dir(), true, true )
  102.     end
  103. end
  104. local function completeEitherEither( shell, nIndex, sText, tPreviousText )
  105.     if nIndex == 1 then
  106.         local tResults = fs.complete( sText, shell.dir(), true, true )
  107.         for n=1,#tResults do
  108.             local sResult = tResults[n]
  109.             if string.sub( sResult, #sResult, #sResult ) ~= "/" then
  110.                 tResults[n] = sResult .. " "
  111.             end
  112.         end
  113.         return tResults
  114.     elseif nIndex == 2 then
  115.         return fs.complete( sText, shell.dir(), true, true )
  116.     end
  117. end
  118. local function completeProgram( shell, nIndex, sText, tPreviousText )
  119.     if nIndex == 1 then
  120.         return shell.completeProgram( sText )
  121.     end
  122. end
  123. local function completeHelp( shell, nIndex, sText, tPreviousText )
  124.     if nIndex == 1 then
  125.         return help.completeTopic( sText )
  126.     end
  127. end
  128. local function completeAlias( shell, nIndex, sText, tPreviousText )
  129.     if nIndex == 2 then
  130.         return shell.completeProgram( sText )
  131.     end
  132. end
  133. local function completePeripheral( shell, nIndex, sText, tPreviousText )
  134.     if nIndex == 1 then
  135.         return completePeripheralName( sText )
  136.     end
  137. end
  138. local tGPSOptions = { "host", "host ", "locate" }
  139. local function completeGPS( shell, nIndex, sText, tPreviousText )
  140.     if nIndex == 1 then
  141.         return completeMultipleChoice( sText, tGPSOptions )
  142.     end
  143. end
  144. local tLabelOptions = { "get", "get ", "set ", "clear", "clear " }
  145. local function completeLabel( shell, nIndex, sText, tPreviousText )
  146.     if nIndex == 1 then
  147.         return completeMultipleChoice( sText, tLabelOptions )
  148.     elseif nIndex == 2 then
  149.         return completePeripheralName( sText )
  150.     end
  151. end
  152. local function completeMonitor( shell, nIndex, sText, tPreviousText )
  153.     if nIndex == 1 then
  154.         return completePeripheralName( sText, true )
  155.     elseif nIndex == 2 then
  156.         return shell.completeProgram( sText )
  157.     end
  158. end
  159. local tRedstoneOptions = { "probe", "set ", "pulse " }
  160. local function completeRedstone( shell, nIndex, sText, tPreviousText )
  161.     if nIndex == 1 then
  162.         return completeMultipleChoice( sText, tRedstoneOptions )
  163.     elseif nIndex == 2 then
  164.         return completeSide( sText )
  165.     end
  166. end
  167. local tDJOptions = { "play", "play ", "stop " }
  168. local function completeDJ( shell, nIndex, sText, tPreviousText )
  169.     if nIndex == 1 then
  170.         return completeMultipleChoice( sText, tDJOptions )
  171.     elseif nIndex == 2 then
  172.         return completePeripheralName( sText )
  173.     end
  174. end
  175. local tPastebinOptions = { "put ", "get ", "run " }
  176. local function completePastebin( shell, nIndex, sText, tPreviousText )
  177.     if nIndex == 1 then
  178.         return completeMultipleChoice( sText, tPastebinOptions )
  179.     elseif nIndex == 2 then
  180.         if tPreviousText[2] == "put" then
  181.             return fs.complete( sText, shell.dir(), true, false )
  182.         end
  183.     end
  184. end
  185. local tChatOptions = { "host ", "join " }
  186. local function completeChat( shell, nIndex, sText, tPreviousText )
  187.     if nIndex == 1 then
  188.         return completeMultipleChoice( sText, tChatOptions )
  189.     end
  190. end
  191. shell.setCompletionFunction( "rom/programs/alias", completeAlias )
  192. shell.setCompletionFunction( "rom/programs/cd", completeDir )
  193. shell.setCompletionFunction( "rom/programs/copy", completeEitherEither )
  194. shell.setCompletionFunction( "rom/programs/delete", completeEither )
  195. shell.setCompletionFunction( "rom/programs/drive", completeDir )
  196. shell.setCompletionFunction( "rom/programs/edit", completeFile )
  197. shell.setCompletionFunction( "rom/programs/eject", completePeripheral )
  198. shell.setCompletionFunction( "rom/programs/gps", completeGPS )
  199. shell.setCompletionFunction( "rom/programs/help", completeHelp )
  200. shell.setCompletionFunction( "rom/programs/id", completePeripheral )
  201. shell.setCompletionFunction( "rom/programs/label", completeLabel )
  202. shell.setCompletionFunction( "rom/programs/list", completeDir )
  203. shell.setCompletionFunction( "rom/programs/mkdir", completeFile )
  204. shell.setCompletionFunction( "rom/programs/monitor", completeMonitor )
  205. shell.setCompletionFunction( "rom/programs/move", completeEitherEither )
  206. shell.setCompletionFunction( "rom/programs/redstone", completeRedstone )
  207. shell.setCompletionFunction( "rom/programs/rename", completeEitherEither )
  208. shell.setCompletionFunction( "rom/programs/shell", completeProgram )
  209. shell.setCompletionFunction( "rom/programs/type", completeEither )
  210. shell.setCompletionFunction( "rom/programs/advanced/bg", completeProgram )
  211. shell.setCompletionFunction( "rom/programs/advanced/fg", completeProgram )
  212. shell.setCompletionFunction( "rom/programs/fun/dj", completeDJ )
  213. shell.setCompletionFunction( "rom/programs/fun/advanced/paint", completeFile )
  214. shell.setCompletionFunction( "rom/programs/http/pastebin", completePastebin )
  215. shell.setCompletionFunction( "rom/programs/rednet/chat", completeChat )
  216.  
  217. -- Run autorun files
  218. if fs.exists( "/rom/autorun" ) and fs.isDir( "/rom/autorun" ) then
  219.     local tFiles = fs.list( "/rom/autorun" )
  220.     table.sort( tFiles )
  221.     for n, sFile in ipairs( tFiles ) do
  222.         if string.sub( sFile, 1, 1 ) ~= "." then
  223.             local sPath = "/rom/autorun/"..sFile
  224.             if not fs.isDir( sPath ) then
  225.                 shell.run( sPath )
  226.             end
  227.         end
  228.     end
  229. end
  230.  
  231. -- Run the user created startup, either from disk drives or the root
  232. local sUserStartup = shell.resolveProgram( "/startup" )
  233. local bEnableDiskStartup = (commands == nil)
  234. if bEnableDiskStartup then
  235.     for n,sName in pairs( peripheral.getNames() ) do
  236.         if disk.isPresent( sName ) and disk.hasData( sName ) then
  237.             local sDiskStartup = shell.resolveProgram( "/" .. disk.getMountPath( sName ) .. "/startup" )
  238.             if sDiskStartup then
  239.                 sUserStartup = sDiskStartup
  240.                 break
  241.             end
  242.         end
  243.     end
  244. end
  245. if sUserStartup then
  246.     shell.run( sUserStartup )
  247. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement