mirror of
https://github.com/mt-mods/home_workshop_modpack.git
synced 2025-07-01 07:50:39 +02:00
add filesystem
This commit is contained in:
7
computers/commands/cd/conf.json
Normal file
7
computers/commands/cd/conf.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "cd",
|
||||
"license": "MIT",
|
||||
"version": 0.1,
|
||||
"engine": 0.4,
|
||||
"help": "move in and out of folders"
|
||||
}
|
25
computers/commands/cd/init.lua
Normal file
25
computers/commands/cd/init.lua
Normal file
@ -0,0 +1,25 @@
|
||||
function cd(pos, input, data)
|
||||
local path = computers.devicepath .. "/" .. minetest.hash_node_position(pos) .. data.element.pwd
|
||||
|
||||
if input and input ~= "" and not input:find("/") then
|
||||
if input == ".." then
|
||||
local uri = data.element.pwd:split("/")
|
||||
uri[#uri] = nil
|
||||
data.element.pwd = "/" .. table.concat(uri, "/")
|
||||
if data.element.pwd == "/" then data.element.pwd = "" end
|
||||
return "sucess"
|
||||
else
|
||||
for _, folder in pairs(minetest.get_dir_list(path, true)) do
|
||||
if folder == input then
|
||||
data.element.pwd = data.element.pwd .. "/" .. input
|
||||
return "sucess"
|
||||
end
|
||||
end
|
||||
return "ERROR: path not found"
|
||||
end
|
||||
else
|
||||
return "invalid or missing input"
|
||||
end
|
||||
end
|
||||
|
||||
return cd
|
@ -2,5 +2,6 @@
|
||||
"name": "echo",
|
||||
"license": "MIT",
|
||||
"version": 0.1,
|
||||
"engine": 0.3
|
||||
"engine": 0.3,
|
||||
"help": "prints out input to the terminal"
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
function echo(input)
|
||||
function echo(pos, input, data)
|
||||
return input
|
||||
end
|
||||
|
||||
|
7
computers/commands/help/conf.json
Normal file
7
computers/commands/help/conf.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "help",
|
||||
"license": "MIT",
|
||||
"version": 0.1,
|
||||
"engine": 0.4,
|
||||
"help": "prints out help"
|
||||
}
|
9
computers/commands/help/init.lua
Normal file
9
computers/commands/help/init.lua
Normal file
@ -0,0 +1,9 @@
|
||||
function help(pos, input, data)
|
||||
local output = ""
|
||||
for command, def in pairs(computers.registered_confs) do
|
||||
output = output .. "\n" .. command .. ": " .. def.help
|
||||
end
|
||||
return output
|
||||
end
|
||||
|
||||
return help
|
7
computers/commands/ls/conf.json
Normal file
7
computers/commands/ls/conf.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "ls",
|
||||
"license": "MIT",
|
||||
"version": 0.1,
|
||||
"engine": 0.4,
|
||||
"help": "lists out all files and folders in the current path"
|
||||
}
|
9
computers/commands/ls/init.lua
Normal file
9
computers/commands/ls/init.lua
Normal file
@ -0,0 +1,9 @@
|
||||
function ls(pos, input, data)
|
||||
local path = computers.devicepath .. "/" .. minetest.hash_node_position(pos) .. data.element.pwd
|
||||
--make dir to be safe
|
||||
minetest.mkdir(path)
|
||||
|
||||
return table.concat(minetest.get_dir_list(path), " ")
|
||||
end
|
||||
|
||||
return ls
|
7
computers/commands/mkdir/conf.json
Normal file
7
computers/commands/mkdir/conf.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "mkdir",
|
||||
"license": "MIT",
|
||||
"version": 0.1,
|
||||
"engine": 0.4,
|
||||
"help": "makes a dir in the current path"
|
||||
}
|
12
computers/commands/mkdir/init.lua
Normal file
12
computers/commands/mkdir/init.lua
Normal file
@ -0,0 +1,12 @@
|
||||
function mkdir(pos, input, data)
|
||||
local path = computers.devicepath .. "/" .. minetest.hash_node_position(pos) .. data.element.pwd
|
||||
|
||||
if input and input ~= "" and not input:find("/") then
|
||||
minetest.mkdir(path .. "/" .. input)
|
||||
return "folder " .. input .. " created"
|
||||
else
|
||||
return "invalid or missing input"
|
||||
end
|
||||
end
|
||||
|
||||
return mkdir
|
7
computers/commands/pwd/conf.json
Normal file
7
computers/commands/pwd/conf.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "pwd",
|
||||
"license": "MIT",
|
||||
"version": 0.1,
|
||||
"engine": 0.4,
|
||||
"help": "list the current path"
|
||||
}
|
7
computers/commands/pwd/init.lua
Normal file
7
computers/commands/pwd/init.lua
Normal file
@ -0,0 +1,7 @@
|
||||
function pwd(pos, input, data)
|
||||
local output = data.element.pwd
|
||||
if output == "" then output = "/" end
|
||||
return output
|
||||
end
|
||||
|
||||
return pwd
|
@ -2,5 +2,6 @@
|
||||
"name": "test",
|
||||
"license": "MIT",
|
||||
"version": 0.1,
|
||||
"engine": 100000000
|
||||
"engine": 100000000,
|
||||
"help": "literally worthless"
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
function test()
|
||||
function test(pos, input)
|
||||
--minetest.chat_send_all("test")
|
||||
return 0
|
||||
end
|
||||
|
7
computers/commands/touch/conf.json
Normal file
7
computers/commands/touch/conf.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"name": "touch",
|
||||
"license": "MIT",
|
||||
"version": 0.1,
|
||||
"engine": 0.4,
|
||||
"help": "creates a file in the current path"
|
||||
}
|
14
computers/commands/touch/init.lua
Normal file
14
computers/commands/touch/init.lua
Normal file
@ -0,0 +1,14 @@
|
||||
function touch(pos, input, data)
|
||||
local path = computers.devicepath .. "/" .. minetest.hash_node_position(pos) .. data.element.pwd
|
||||
--make dir to be safe
|
||||
minetest.mkdir(path)
|
||||
|
||||
if input and input ~= "" and not input:find("/") then
|
||||
minetest.safe_file_write(path .. "/" .. input, "")
|
||||
return "file " .. input .. " created"
|
||||
else
|
||||
return "invalid or missing input"
|
||||
end
|
||||
end
|
||||
|
||||
return touch
|
Reference in New Issue
Block a user