OctOS: Add ls and cat commands

Allow listing the contents of a directory
and printing the contents of a file.
master
octacian 2018-05-31 11:28:31 -07:00
parent 613657d454
commit 84ea1850ce
No known key found for this signature in database
GPG Key ID: E84291D11A3509B5
4 changed files with 28 additions and 0 deletions

4
octos/bin/cat Normal file
View File

@ -0,0 +1,4 @@
name = cat
description = Print the contents of a file
params = [path]
exec = os/exec/cat.lua

4
octos/bin/ls Normal file
View File

@ -0,0 +1,4 @@
name = ls
description = List the contents of a directory
params = [path]
exec = os/exec/ls.lua

10
octos/exec/cat.lua Normal file
View File

@ -0,0 +1,10 @@
local path = ...
path = path[1]
if path then
if fs.exists(path) then
print(fs.read(path))
end
else
print("Must specify path (see help cat)")
end

10
octos/exec/ls.lua Normal file
View File

@ -0,0 +1,10 @@
local path = ...
path = path[1]
if path then
local contents = fs.list(path)
local result = table.concat(contents.files, " ") .. " " .. table.concat(contents.subdirs, " ")
print(result)
else
print("Must specify path (see help ls)")
end