chore: Detect missing final newline in configs read

These lines will be not be processed by `read`, emit a warning to raise awareness.
This commit is contained in:
polarathene 2024-01-24 17:13:28 +13:00
parent ed1e1ebbd3
commit 3db863aa8e
1 changed files with 6 additions and 0 deletions

View File

@ -17,6 +17,12 @@ function _escape_for_sed() {
# Returns input after filtering out lines that are:
# empty, white-space, comments (`#` as the first non-whitespace character)
function _get_valid_lines_from_file() {
# Correctly detect missing final newline:
# https://stackoverflow.com/questions/38746/how-to-detect-file-ends-in-newline#comment82380232_25749716
if [[ $(tail -c1 "${1}" | wc -l) -gt 0 ]]; then
_log 'warn' "${1} is missing a final newline. The last line will not be processed!"
fi
grep --extended-regexp --invert-match "^\s*$|^\s*#" "${1}" || true
}