Skip to content

Commit 7141565

Browse files
committed
common: add helper log_file_bat()
- so I don't keep spreading conditionals everywhere Signed-off-by: Ricardo Pardini <[email protected]>
1 parent d20058a commit 7141565

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

bash/common.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,25 @@ function log_tree() {
3434
fi
3535
}
3636

37+
# Helper for showing the contents of a file (using bat, if installed)
38+
function log_file_bat() {
39+
declare file="${1}"
40+
shift
41+
declare level="${1}"
42+
shift
43+
[[ "${level}" == "debug" && "${DEBUG}" != "yes" ]] && return # Skip debugs unless DEBUG=yes is set in the environment
44+
log "${level}" "${@}" "-- file ${file}:"
45+
declare extra_bat_args=()
46+
if [[ -n "${bat_language}" ]]; then
47+
extra_bat_args+=("--language=${bat_language}")
48+
fi
49+
if command -v bat > /dev/null; then
50+
bat --color=always "${extra_bat_args[@]}" "${file}"
51+
else
52+
log "${level}" "'bat' utility not installed; install it to see file contents in logs."
53+
fi
54+
}
55+
3756
function install_dependencies() {
3857
declare extra="${1}"
3958

0 commit comments

Comments
 (0)