Skip to content

Instantly share code, notes, and snippets.

@allmarkedup
Last active September 8, 2025 17:19
Show Gist options
  • Select an option

  • Save allmarkedup/c2f6caf65e7eed9ff9047169bb720a55 to your computer and use it in GitHub Desktop.

Select an option

Save allmarkedup/c2f6caf65e7eed9ff9047169bb720a55 to your computer and use it in GitHub Desktop.
Add missing trailing newline to all files in a git repo #codesnippet

Insert missing newlines into all files in git repo

git ls-files -z | while IFS= read -rd '' f; do if file --brief --mime-encoding "$f" | grep -qv binary; then tail -c1 < "$f" | read -r _ || echo >> "$f"; fi; done

Filter by extension type

In this example, .erb, files only:

git ls-files '**/*.erb' -z | while IFS= read -rd '' f; do if file --brief --mime-encoding "$f" | grep -qv binary; then tail -c1 < "$f" | read -r _ || echo >> "$f"; fi; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment