Commit 4a5a4bb8 authored by Vincent Tam's avatar Vincent Tam

Post: added two posts on coreutils

parent cf59663f
Pipeline #41172117 passed with stages
in 32 seconds
---
title: "2018 12 23 Detect Missing Eof"
title: "Detect Missing EOF"
date: 2018-12-23T12:10:06+01:00
type: post
categories:
- technical support
tags:
- Linux
draft: true
---
for file in `git ls-files`; do grep -Iq . $file && if ! newline_at_eof $file; then; else echo $file && tail -c10 $file && echo '\n'; fi; done
While editing files on GitHub/Gitlab, missing an empty line at the bottom of a
file in the buffer will result in no newline at the end of file. In the case of
regular text files, this _isn't_ consistent with the POSIX standards.
```sh
for file in `git ls-files`; do
grep -Iq . $file && if ! newline_at_eof $file; then; else echo $file; fi
done
```
Fred has provided [a shell script for detecting EOF][eof] on Stack Overflow.
I've replaced `bash` with `sh` because I'm using Zsh.
```sh
#!/bin/zsh
if [ -z "$(tail -c 1 "$1")" ]
then
echo "Newline at end of file!"
exit 1
else
echo "No newline at end of file!"
exit 0
fi
```
[eof]: https://stackoverflow.com/a/34944104/3184351
......@@ -30,5 +30,9 @@ while read -d $'\0' file; do
done
```
A list of matching files is piped to the `while` loop which iterates through
each item delimited by the null character `'\0'`. The shell expansion
`${file%.*}` trim off the file extension.
[old]: https://vincenttam.github.io/blog/2015/08/22/used-more-bash-utilities/
[Facebook]: https://facebook.com
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment