From 6fe9e96eee99361013f3a49a38775d404dbd3cca Mon Sep 17 00:00:00 2001 From: Jason Gross Date: Wed, 1 Nov 2023 13:54:51 -0700 Subject: [PATCH] Post both head and tail of file when truncating Fixes #31 --- coqbot-config.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/coqbot-config.sh b/coqbot-config.sh index d194cd7..8b83c17 100644 --- a/coqbot-config.sh +++ b/coqbot-config.sh @@ -192,10 +192,14 @@ function print_file() { fname="$6" end_code="$7" filesize="$(stat -c%s "${fname}")" + head_tail_separator="$(printf '\n\n[...]\n\n')" if (( filesize > max_file_size )); then - filesize_pretty="$(numfmt --to=iec-i --suffix=B "${filesize}")" - max_file_size_pretty="$(numfmt --to=iec-i --suffix=B "${max_file_size}")" case "${head_tail}" in + head-tail) + max_filesize="$(( ( ${max_file_size} - ${#head_tail_separator} ) / 2 ))" + contents="$(head -c ${max_file_size} "${fname}")${head_tail_separator}$(tail -c ${max_file_size} "${fname}")" + truncated="first and last " + ;; head) contents="$(head -c ${max_file_size} "${fname}")" truncated="" @@ -209,6 +213,8 @@ function print_file() { truncated="" ;; esac + filesize_pretty="$(numfmt --to=iec-i --suffix=B "${filesize}")" + max_file_size_pretty="$(numfmt --to=iec-i --suffix=B "${max_file_size}")" title="${title} (truncated to ${truncated}${max_file_size_pretty}; full ${filesize_pretty} file on GitHub Actions Artifacts under $(realpath --relative-to "$DIR" "${fname}"))" else title="${title}${extra_title_unless_truncated}"