Last active
August 29, 2015 14:05
-
-
Save wteuber/7696eb4138b616daeb0d to your computer and use it in GitHub Desktop.
No newline at end of file? These bash snippets will help you add new line at end of files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define file extensions that should be regarded | |
EXT=(css ejs erb gemspec gitignore html js json md mustache rake rb rdoc rspec ru scss sh sql txt ui xml xsd yardopts yml) | |
EXT=$(printf "\|%s" "${EXT[@]}") | |
EXT=${EXT:2} | |
# git: | |
git ls-files "*.*" | grep "\.\($EXT\)$" | sed "s/^/\'/; s/$/\'/;" | xargs sed -i -e '$a\' | |
# plain: | |
find . -name "*.*" | grep "\.\($EXT\)$" | sed "s/^/\'/; s/$/\'/;" | xargs sed -i -e '$a\' | |
# Explained: | |
# EXT=(ext1 ext2 ...) # Array of strings that will be used as file extensions | |
# | |
# EXT=$(printf "\|%s" "${EXT[@]}") # Join elements with '\|' for file name filtering later | |
# | |
# EXT=${EXT:2} # Prepend first element of file extensions array (without leading '\|') | |
# | |
# find . -name "*.*" # List all files recursivly that contain a '.' | |
# git ls-files "*.*" # List all tracked files recursivly that contain a '.' | |
# | |
# grep "\.\($EXT\)$" # Filter output for defined file extensions | |
# | |
# sed "s/^/\'/; s/$/\'/;" # Quote file names | |
# | |
# xargs sed -i -e '$a\' # Actually add "\n" at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment