hachem.wtf
aboutsummaryrefslogtreecommitdiff
path: root/gils/tail.rv
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-10-06 12:49:46 +0200
committerhachem <im@hachem.wtf>2026-10-06 12:49:46 +0200
commit5d4a723a5f157c0ed38a348099a600d1d21c3c2b (patch)
tree70e5fdf560a64cd0eb3a13d88ce046ddd29fd077 /gils/tail.rv
parent52dab7fc85d877e80e3032f0afabae906adebad8 (diff)
feat: gils core utils and other shit
Diffstat (limited to 'gils/tail.rv')
-rw-r--r--gils/tail.rv29
1 files changed, 29 insertions, 0 deletions
diff --git a/gils/tail.rv b/gils/tail.rv
new file mode 100644
index 0000000..9cd5647
--- /dev/null
+++ b/gils/tail.rv
@@ -0,0 +1,29 @@
+# my tail is 16 inches long
+# and its between my legs
+
+fn file_lines(path) do
+ const size = fs:size(path)
+ if size < 0 return :nil
+ const contents = if size > 0 fs:read_bytes(path, 0, size) else ""
+ const raw_lines = contents:split("\n")
+ let result = {}
+ for index in 0..raw_lines:len() do
+ if (index < raw_lines:len() - 1 or raw_lines[index]:len() > 0) result:push(raw_lines[index])
+ end
+ return result
+end
+
+const context = env.ctx
+if context.argv:len() < 2 do puts("usage: tail [n] <path>\n") end
+else do
+ let limit = 10
+ let path_arg = context.argv[1]
+ if (context.argv:len() >= 3 and parse_pid(context.argv[1]) >= 0) do limit = parse_pid(context.argv[1]) path_arg = context.argv[2] end
+ const lines = file_lines(abspath(path_arg))
+ if lines == :nil do puts("tail: no such file\n") end
+ else do
+ let start = lines:len() - limit
+ if start < 0 do start = 0 end
+ for index in start..lines:len() do puts("#{lines[index]}\n") end
+ end
+end