Bash: crlf can check single file.

This commit is contained in:
Artem Sapegin 2013-02-12 10:03:26 +04:00
parent 9108b2dc1b
commit bb1d21345c

View File

@ -152,13 +152,26 @@ function yay() {
} }
# Find files with Windows line endings (and convert then to Unix in force mode) # Find files with Windows line endings (and convert then to Unix in force mode)
# USAGE: crlf [--force] # USAGE: crlf [file] [--force]
function crlf() { function crlf() {
local force=
# Single file
if [ "$1" != "" ] && [ "$1" != "--force" ]; then
[ "$2" == "--force" ] && force=1 || force=0
_crlf_file $1 $force
return
fi
# All files
[ "$1" == "--force" ] && force=1 || force=0 [ "$1" == "--force" ] && force=1 || force=0
for file in $(find . -type f -not -path "*/.git/*" -not -path "*/node_modules/*" | xargs file | grep ASCII | cut -d: -f1); do for file in $(find . -type f -not -path "*/.git/*" -not -path "*/node_modules/*" | xargs file | grep ASCII | cut -d: -f1); do
grep -q $'\x0D' "$file" && echo "$file" && [ $force ] && dos2unix "$file" _crlf_file $file $force
done done
} }
function _crlf_file() {
grep -q $'\x0D' "$1" && echo "$1" && [ $2 ] && dos2unix "$1"
}
# Backup remote MySQL database to ~/Backups/hostname/dbname_YYYY-MM-DD.sql.gz # Backup remote MySQL database to ~/Backups/hostname/dbname_YYYY-MM-DD.sql.gz
# USAGE: mysql-dump <ssh_hostname> <mysql_database> [mysql_username] [mysql_host] # USAGE: mysql-dump <ssh_hostname> <mysql_database> [mysql_username] [mysql_host]