-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patheasystartup.lua
69 lines (54 loc) · 1.66 KB
/
easystartup.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
local completion = require("cc.completion")
local function path_completion(text)
if fs.exists(text) and fs.isDir(text) then
return completion.choice(text, fs.list(text))
else
return completion.choice(text, fs.list(""))
end
end
term.clear()
term.setCursorPos(1,1)
print("Welcome to EasyStartup!")
print("Enter the desired file to auto startup:")
local file = read(nil, nil, path_completion)
print("Enter a delay: (in seconds)")
local delay = read(nil, nil, nil, "1")
print("Restart on erroring? (y/n) (ignores Terminated)")
local pcall_mode = read(nil, nil, nil, "y")
local startup_file = io.open("startup.lua", "w")
local startup_program = ([[
print("Starting Program '&p' in ]]..delay..[[s")
sleep(]]..delay..[[)
shell.run("&p")
]])
local startup_program_pcall = ([[
while true do
local stat, err = pcall(function()
print("Starting Program '&p' in ]]..delay..[[s")
sleep(]]..delay..[[)
if not shell.run("&p") then
error("Program Errored")
end
end)
if not stat then
print(err)
print("Restarting in ]]..(1)..[[s")
sleep(]]..(1)..[[)
if err == "Terminated" then
print("Program Terminated") break
end
end
end
]])
if pcall_mode == "y" or pcall_mode == "yes" or pcall_mode == "true" then
startup_program = startup_program_pcall:gsub("&p", file)
else
startup_program = startup_program:gsub("&p", file)
end
startup_file:write(startup_program)
startup_file:close()
print("Done!")
fs.delete("easystartup.lua")
print("Restarting computer..")
sleep(0.5)
os.reboot()