From beb3a3a28a009db4eebb292d7ac17276e7267f08 Mon Sep 17 00:00:00 2001 From: Leonard Kugis Date: Sun, 20 Sep 2026 16:40:46 +0200 Subject: . --- tools/fs_cat.sh | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'tools/fs_cat.sh') diff --git a/tools/fs_cat.sh b/tools/fs_cat.sh index d02ca21..16bd592 100755 --- a/tools/fs_cat.sh +++ b/tools/fs_cat.sh @@ -3,7 +3,10 @@ set -uo pipefail # @describe Read the contents of a file at the specified path. # Use this when you need to examine the contents of an existing file. +# Without --offset and --limit the whole file is printed. # @option --path! The path of the file to read +# @option --offset Start reading at byte offset (0-based, default: 0) +# @option --limit Maximum number of bytes to read # @env LLM_OUTPUT=/dev/stdout The output path OUT="${LLM_OUTPUT:-/dev/stdout}" @@ -34,10 +37,24 @@ main() { err "file appears to be binary (NUL bytes detected): $path" fi - head -c "$MAX_BYTES" "$path" | sanitize >> "$OUT" + offset="${argc_offset:-0}" + limit="${argc_limit:-}" + + # Begrenzung auf MAX_BYTES + if [[ -z "$limit" ]]; then + limit="$MAX_BYTES" + elif [[ "$limit" -gt "$MAX_BYTES" ]]; then + limit="$MAX_BYTES" + fi + + if [[ "$offset" -eq 0 ]]; then + head -c "$limit" "$path" | sanitize >> "$OUT" + else + dd if="$path" bs=1 skip="$offset" count="$limit" status=none 2>/dev/null | sanitize >> "$OUT" + fi + exit 0 } eval "$(argc --argc-eval "$0" "$@")" main - -- cgit v1.2.3