mirror of https://github.com/Hilbis/Hilbish
feat: add builtins clear, exec and cat (#208)
* feat: add clear and exec command * docs: add builtins to changelog * feat: add cat commandreuse-runner-2
parent
cc6e5d01dd
commit
0d32a10ca3
@ -0,0 +1,25 @@
|
||||
local commander = require 'commander'
|
||||
local fs = require 'fs'
|
||||
|
||||
commander.register('cat', function(args)
|
||||
local exit = 0
|
||||
|
||||
if #args == 0 then
|
||||
print [[
|
||||
usage: cat [file]...]]
|
||||
end
|
||||
|
||||
for _, fName in ipairs(args) do
|
||||
local f = io.open(fName)
|
||||
if f == nil then
|
||||
exit = 1
|
||||
print(string.format('cat: %s: no such file or directory', fName))
|
||||
goto continue
|
||||
end
|
||||
|
||||
io.write(f:read '*a')
|
||||
::continue::
|
||||
end
|
||||
io.flush()
|
||||
return exit
|
||||
end)
|
@ -0,0 +1,7 @@
|
||||
local ansikit = require 'ansikit'
|
||||
local commander = require 'commander'
|
||||
|
||||
commander.register('clear', function()
|
||||
ansikit.clear(true)
|
||||
ansikit.cursorTo(0, 0)
|
||||
end)
|
@ -0,0 +1,5 @@
|
||||
local commander = require 'commander'
|
||||
|
||||
commander.register('exec', function(args)
|
||||
hilbish.exec(args[1])
|
||||
end)
|
Loading…
Reference in new issue