From bb1d21345c8ddaa71e5c3e57f955f6dc82aee4d6 Mon Sep 17 00:00:00 2001 From: Artem Sapegin Date: Tue, 12 Feb 2013 10:03:26 +0400 Subject: [PATCH] Bash: crlf can check single file. --- includes/bash_functions.bash | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/includes/bash_functions.bash b/includes/bash_functions.bash index cf97ac5..5cad0db 100644 --- a/includes/bash_functions.bash +++ b/includes/bash_functions.bash @@ -152,13 +152,26 @@ function yay() { } # Find files with Windows line endings (and convert then to Unix in force mode) -# USAGE: crlf [--force] +# USAGE: crlf [file] [--force] 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 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 } +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 # USAGE: mysql-dump [mysql_username] [mysql_host]