diff --git a/CHANGELOG.md b/CHANGELOG.md index 1fdae95..738991a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/nature/commands/cat.lua b/nature/commands/cat.lua new file mode 100644 index 0000000..132db5f --- /dev/null +++ b/nature/commands/cat.lua @@ -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) diff --git a/nature/commands/clear.lua b/nature/commands/clear.lua new file mode 100644 index 0000000..68aa197 --- /dev/null +++ b/nature/commands/clear.lua @@ -0,0 +1,7 @@ +local ansikit = require 'ansikit' +local commander = require 'commander' + +commander.register('clear', function() + ansikit.clear(true) + ansikit.cursorTo(0, 0) +end) diff --git a/nature/commands/exec.lua b/nature/commands/exec.lua new file mode 100644 index 0000000..d279e31 --- /dev/null +++ b/nature/commands/exec.lua @@ -0,0 +1,5 @@ +local commander = require 'commander' + +commander.register('exec', function(args) + hilbish.exec(args[1]) +end)