mirror of https://github.com/Hilbis/Hilbish
feat: add cat command
parent
f3964ce389
commit
373d2e4f82
|
@ -75,7 +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
|
- 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])
|
random errors introduced with the new Lua runtime (see [#197])
|
||||||
- `bait.release(name, catcher)` removes `handler` for the named `event`
|
- `bait.release(name, catcher)` removes `handler` for the named `event`
|
||||||
- `exec` and `clear` builtin commands
|
- `exec`, `clear` and `cat` builtin commands
|
||||||
|
|
||||||
[#197]: https://github.com/Rosettea/Hilbish/issues/197
|
[#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)
|
Loading…
Reference in New Issue