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 commandpull/312/head
parent
cc6e5d01dd
commit
0d32a10ca3
|
@ -75,6 +75,7 @@ disables commands being added to history.
|
|||
- A new and "safer" event emitter has been added. This causes a performance deficit, but avoids a lot of
|
||||
random errors introduced with the new Lua runtime (see [#197])
|
||||
- `bait.release(name, catcher)` removes `handler` for the named `event`
|
||||
- `exec`, `clear` and `cat` builtin commands
|
||||
|
||||
[#197]: https://github.com/Rosettea/Hilbish/issues/197
|
||||
|
||||
|
|
|
@ -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