add filesystem

This commit is contained in:
unknown
2022-02-13 00:31:20 -05:00
parent ef2ceed755
commit 4cfacb1abc
19 changed files with 148 additions and 16 deletions

View File

@ -0,0 +1,7 @@
{
"name": "cd",
"license": "MIT",
"version": 0.1,
"engine": 0.4,
"help": "move in and out of folders"
}

View 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

View File

@ -2,5 +2,6 @@
"name": "echo",
"license": "MIT",
"version": 0.1,
"engine": 0.3
"engine": 0.3,
"help": "prints out input to the terminal"
}

View File

@ -1,4 +1,4 @@
function echo(input)
function echo(pos, input, data)
return input
end

View File

@ -0,0 +1,7 @@
{
"name": "help",
"license": "MIT",
"version": 0.1,
"engine": 0.4,
"help": "prints out help"
}

View 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

View 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"
}

View 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

View File

@ -0,0 +1,7 @@
{
"name": "mkdir",
"license": "MIT",
"version": 0.1,
"engine": 0.4,
"help": "makes a dir in the current path"
}

View 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

View File

@ -0,0 +1,7 @@
{
"name": "pwd",
"license": "MIT",
"version": 0.1,
"engine": 0.4,
"help": "list the current path"
}

View 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

View File

@ -2,5 +2,6 @@
"name": "test",
"license": "MIT",
"version": 0.1,
"engine": 100000000
"engine": 100000000,
"help": "literally worthless"
}

View File

@ -1,4 +1,4 @@
function test()
function test(pos, input)
--minetest.chat_send_all("test")
return 0
end

View File

@ -0,0 +1,7 @@
{
"name": "touch",
"license": "MIT",
"version": 0.1,
"engine": 0.4,
"help": "creates a file in the current path"
}

View 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