Skip to content

Commit

Permalink
feature: bash: add bash_ensure_nl_at_eof
Browse files Browse the repository at this point in the history
Ensure file ends with newline.

Follows always symlinks.
  • Loading branch information
maage committed May 17, 2023
1 parent ebd43d4 commit 268b260
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions shared/macros/10-bash.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -1465,6 +1465,22 @@ cce="{{{ cce_identifiers['cce'] }}}"
{{%- endmacro -%}}


{{#
Ensure file ends with newline

Do not modify file at all if there already is newline. Always follows
symlinks.

:param file: file to check
#}}
{{%- macro bash_ensure_nl_at_eof(file) -%}}
{{#- Plain sed '$a\' updates stat even if it dones not change the file. -#}}
if [[ -s "{{{ file }}}" ]] && [[ -n "$(tail -c 1 -- "{{{ file }}}")" ]]; then
LC_ALL=C sed -i --follow-symlinks '$a\' "{{{ file }}}"
fi
{{%- endmacro -%}}


{{#
Macro to replace configuration setting in config file or add the configuration setting if
it does not exist.
Expand Down

0 comments on commit 268b260

Please sign in to comment.