added the touch app
This commit is contained in:
+2
-2
@@ -1,11 +1,11 @@
|
|||||||
local files = {...}
|
local files = { ... }
|
||||||
local shell = require("shell")
|
local shell = require("shell")
|
||||||
local fs = require("filesystem")
|
local fs = require("filesystem")
|
||||||
if not files or not files[1] then
|
if not files or not files[1] then
|
||||||
shell.run("help cat")
|
shell.run("help cat")
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
for _, file in ipairs(files) do
|
for _, file in ipairs(files) do
|
||||||
if file:sub(1, 1) ~= "/" then
|
if file:sub(1, 1) ~= "/" then
|
||||||
file = fs.concat(shell.getWorkingDirectory(), file)
|
file = fs.concat(shell.getWorkingDirectory(), file)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
Usage: touch [FLAGS] [FILE]
|
||||||
|
Creates a file with empty content.
|
||||||
|
|
||||||
|
FLAGS Specifies extra options when executing the command.
|
||||||
|
-o, --overwrite Allows emptying out a file if it already exists.
|
||||||
|
FILE The path of the file to create.²
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
local cliparse = require("cliparse")
|
||||||
|
cliparse.config({
|
||||||
|
["o"] = 0,
|
||||||
|
["overwrite"] = 0,
|
||||||
|
})
|
||||||
|
local parsed = cliparse.parse(...)
|
||||||
|
local file = parsed.args[1]
|
||||||
|
local fs = require("filesystem")
|
||||||
|
local shell = require("shell")
|
||||||
|
|
||||||
|
if not file then
|
||||||
|
return shell.run("help touch")
|
||||||
|
end
|
||||||
|
|
||||||
|
if file:sub(1, 1) ~= "/" then
|
||||||
|
file = fs.concat(shell.getWorkingDirectory(), file)
|
||||||
|
end
|
||||||
|
|
||||||
|
if fs.exists(file) and not (parsed.flags.o or parsed.flags.overwrite) then
|
||||||
|
return print("\x1b[91mFile already exists.\n│ To empty file contents, use -o.")
|
||||||
|
end
|
||||||
|
|
||||||
|
local handle = fs.open(file, "w")
|
||||||
|
handle:write("") -- just in case
|
||||||
|
handle:close()
|
||||||
Reference in New Issue
Block a user