diff options
| author | hachem <im@hachem.wtf> | 2026-10-06 12:49:46 +0200 |
|---|---|---|
| committer | hachem <im@hachem.wtf> | 2026-10-06 12:49:46 +0200 |
| commit | 5d4a723a5f157c0ed38a348099a600d1d21c3c2b (patch) | |
| tree | 70e5fdf560a64cd0eb3a13d88ce046ddd29fd077 /gils/gils.rv | |
| parent | 52dab7fc85d877e80e3032f0afabae906adebad8 (diff) | |
feat: gils core utils and other shit
Diffstat (limited to 'gils/gils.rv')
| -rw-r--r-- | gils/gils.rv | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/gils/gils.rv b/gils/gils.rv new file mode 100644 index 0000000..1a61cc5 --- /dev/null +++ b/gils/gils.rv @@ -0,0 +1,50 @@ +# gils: better than Gnu utILS +global commands = {} + +fn register(usage, group, help, handler) do + const name = usage:split(" ")[0] + commands:push({ name = name, usage = usage, group = group, help = help, handler = handler }) +end + +fn lookup(name) do + for index in 0..commands:len() do + if commands[index].name == name return commands[index] + end + return :nil +end + +fn make_ctx(line, argv) do + const name = argv[0] + let rest = "" + const cut = name:len() + 1 + if line:len() > cut do rest = line[cut..] end + return { line = line, argv = argv, rest = rest } +end + +# scripts read their args off env.ctx, stashed here before eval +global env = { ctx = :nil } + +# working dir + path resolver, shared by every gils tool and the shell. lives +# here so its declared before anything that uses it gets concatenated +global wd = { path = "/" } + +global abspath = fn(arg) do + if arg:len() == 0 return wd.path + let path = arg + if arg[0] != "/" do + if wd.path == "/" do path = "/#{arg}" end + else do path = "#{wd.path}/#{arg}" end + end + while (path:len() > 1 and path[path:len() - 1] == "/") do path = path[0..(path:len() - 1)] end + return path +end + +fn run_script(name, ctx) do + const path = "/bin/#{name}.rv" + const size = fs:size(path) + if size < 0 return :false + env.ctx = ctx + const error_msg = eval_script(fs:read_bytes(path, 0, size)) + if error_msg != :nil do puts("#{name}: #{error_msg}\n") end + return :true +end |
