Skip to content

Commit

Permalink
add file/ensure_newline
Browse files Browse the repository at this point in the history
@briceburg TODO - test on os x
  • Loading branch information
briceburg committed Mar 1, 2017
1 parent af1e277 commit 9ee086b
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,11 @@ file/interpolate(){
echo "$replace" >> "$file"
fi
}

# file/ensure_newline - appends a newline if a file does not end in newline
# usage: file/ensure_newline <path>
file/ensure_newline(){
local file="$1"
local junk
tail -c1 "$file" | read -r junk || echo >> "$file"
}

0 comments on commit 9ee086b

Please sign in to comment.