diff options
| author | Leonard Kugis <leonard@kug.is> | 2026-09-20 16:40:46 +0200 |
|---|---|---|
| committer | Leonard Kugis <leonard@kug.is> | 2026-09-20 16:40:46 +0200 |
| commit | beb3a3a28a009db4eebb292d7ac17276e7267f08 (patch) | |
| tree | 63fee89618ff13db07dc889256040cec0164047f /tools | |
| parent | 4998bb433b9c7baa88e3e3d3e843c0ccbbef9f95 (diff) | |
| download | llm-functions-docker-beb3a3a28a009db4eebb292d7ac17276e7267f08.tar.gz | |
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/fs_cat.sh | 21 |
1 files changed, 19 insertions, 2 deletions
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 <NUM> Start reading at byte offset (0-based, default: 0) +# @option --limit <NUM> 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 - |
