Commit 9fb45bb1 authored by Vincent Tam's avatar Vincent Tam

Post: upcoming fixed missing newline at EOF

parent 0f907a26
Pipeline #29418500 passed with stages
in 36 seconds
title: "Missing Newline at EOL"
subtitle: "Bash detection for dirty EOL and batch editing"
date: 2018-09-05T00:31:02+02:00
type: post
- blogging
draft: false
### Background
Despite my experience in [Vim], the multi-cursor functionality in
[Sublime Text 3][st3] has seduced my to change my editor.
Unlike [Vim], a nonempty new line at the end of [Sublime Text 3][st3]
file buffer causes the file to end _without_ a newline character. In fact,
it's a _POSIX standard_ to include a newline character at the EOL (end of
file). (c.f. [No Newline at End of File][bot])
### Problem
_Unaware_ of the above POSIX standard and [Sublime Text 3][st3] convention,
I have edited many lines of code in the repository for this blog and the one for
my custom [Beautiful Hugo][bh]. These edited files <span class="fa-stack"><i
class="far fa-file fa-stack-1x" aria-hidden></i><i class="fa fa-pencil
fa-stack-1x" aria-hidden></i></span> were _almost everywhere_ in these
repositories, and they _polluted_ their remote counterparts on GitLab <i
class="fab fa-gitlab" aria-hidden></i>.
### Solution
#### Core part
It's possible to write shell script which appends a newline provided that the
last character `tail -c 1 $1` matches an empty string '', but I prefer a
oneline solution.
#### A low-level attempt
[Git <i class="fab fa-git" aria-hidden></i>][git] has a low-level command `git
ls-files` to list the files. However, this _didn't_ work well with my `grep`
command for omitting image files <i class="far fa-file-image" aria-hidden></i>
due to the presence of the submodule for the theme.
<i class="fas fa-info-circle" aria-hidden></i> Even though the installation
instructions of [Beautiful Hugo][bh] suggest cloning _independently_, doing so
will lead to failure during GitLab CI/CD. Therefore, one has better follow the
official [Hugo]'s approach: grab the theme as a Git submodule.
$ pwd
$ for f in `git grep --cached -Il ''`; do if [ "$(tail -c 1 $f)" != '' ]; then
for then> echo >> $f; fi; done
git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
(use "git push" to publish your local commits)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: content/page/bash-commands/
modified: content/post/2018-07-07-upgraded-to-linux-mint-19/
modified: content/post/
modified: content/post/2018-07-23-fujitsu-lh532-keyboard-cleaning/
modified: content/post/2018-07-26-web-image-optimisation-with-gimp/
modified: content/post/
modified: content/post/2018-08-23-brighten-image-with-gimp/
modified: layouts/partials/footer_custom.html
modified: layouts/partials/head_custom.html
modified: static/css/custom.css
modified: static/css/print.min.css
modified: static/google191a8de293cb8fe1.html
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment