Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix exit codes on fix command & BSD compatibility #22

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions bin/file-cr
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,18 @@ if [ "${MY_LST}" = "1" ]; then
fi


if [ "${MY_FIX}" = "1" ]; then
printf "%s\n" "${output}"

if [[ $output =~ ^FAILED\s: ]]; then
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
exit 1
else
printf "${CLR_SUC}[OK] %s${CLR_CLS}\n" "${MY_FINISH_OK}"
exit 0
fi
fi

if [ "${output}" != "" ]; then
printf "%s\n" "${output}"
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
Expand Down
12 changes: 12 additions & 0 deletions bin/file-crlf
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,18 @@ if [ "${MY_LST}" = "1" ]; then
fi


if [ "${MY_FIX}" = "1" ]; then
printf "%s\n" "${output}"

if [[ $output =~ ^FAILED\s: ]]; then
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
exit 1
else
printf "${CLR_SUC}[OK] %s${CLR_CLS}\n" "${MY_FINISH_OK}"
exit 0
fi
fi

if [ "${output}" != "" ]; then
printf "%s\n" "${output}"
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
Expand Down
12 changes: 12 additions & 0 deletions bin/file-empty
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,18 @@ if [ "${MY_LST}" = "1" ]; then
fi


if [ "${MY_FIX}" = "1" ]; then
printf "%s\n" "${output}"

if [[ $output =~ ^FAILED\s: ]]; then
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
exit 1
else
printf "${CLR_SUC}[OK] %s${CLR_CLS}\n" "${MY_FINISH_OK}"
exit 0
fi
fi

if [ "${output}" != "" ]; then
printf "%s\n" "${output}"
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
Expand Down
16 changes: 14 additions & 2 deletions bin/file-nullbyte-char
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ MY_CHECK="if cat -n \"\$1\" | sed -n \"/${MY_REG}/p\" | grep -aq \"^[[:space:]]*
# Can this check fix the problems?
ENABLE_FIX=1

#MY_FIX_CMD="grep -aq \"${MY_REG}\" \"\$1\" && (sed -i\"\" \"s/${MY_REG}//g\" \"\$1\" && echo \"Fixing: \$1\" || echo \"FAILED: \$1\") || true"
MY_FIX_CMD="if cat -n \"\$1\" | sed -n \"/${MY_REG}/p\" | grep -aq \"^[[:space:]]*[0-9]\"; then (sed -i\"\" \"s/${MY_REG}//g\" \"\$1\" && echo \"Fixing: \$1\" || echo \"FAILED: \$1\"); else true; fi"
#MY_FIX_CMD="grep -aq \"${MY_REG}\" \"\$1\" && ((TMP_FILE=\$(mktemp); sed \"s/${MY_REG}//g\" \"\$1\" > \"\${TMP_FILE}\" && mv \"\${TMP_FILE}\" \"\$1\"; ec=\$?; rm -f \"\${TMP_FILE}\"; exit \$ec) && echo \"Fixing: \$1\" || echo \"FAILED: \$1\") || true"
MY_FIX_CMD="if cat -n \"\$1\" | sed -n \"/${MY_REG}/p\" | grep -aq \"^[[:space:]]*[0-9]\"; then ((TMP_FILE=\$(mktemp); sed \"s/${MY_REG}//g\" \"\$1\" > \"\${TMP_FILE}\" && mv \"\${TMP_FILE}\" \"\$1\"; ec=\$?; rm -f \"\${TMP_FILE}\"; exit \$ec) && echo \"Fixing: \$1\" || echo \"FAILED: \$1\"); else true; fi"

# Command to be displayed for --info
MY_INFO="file -v 2>&1 | grep -E '(([0-9]+)(\.))+'"
Expand Down Expand Up @@ -909,6 +909,18 @@ if [ "${MY_LST}" = "1" ]; then
fi


if [ "${MY_FIX}" = "1" ]; then
printf "%s\n" "${output}"

if [[ $output =~ ^FAILED\s: ]]; then
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
exit 1
else
printf "${CLR_SUC}[OK] %s${CLR_CLS}\n" "${MY_FINISH_OK}"
exit 0
fi
fi

if [ "${output}" != "" ]; then
printf "%s\n" "${output}"
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
Expand Down
12 changes: 12 additions & 0 deletions bin/file-trailing-newline
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,18 @@ if [ "${MY_LST}" = "1" ]; then
fi


if [ "${MY_FIX}" = "1" ]; then
printf "%s\n" "${output}"

if [[ $output =~ ^FAILED\s: ]]; then
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
exit 1
else
printf "${CLR_SUC}[OK] %s${CLR_CLS}\n" "${MY_FINISH_OK}"
exit 0
fi
fi

if [ "${output}" != "" ]; then
printf "%s\n" "${output}"
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
Expand Down
14 changes: 13 additions & 1 deletion bin/file-trailing-single-newline
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ MY_CHECK="aci-trailing-newline -1 \"\$1\" || echo \"\$1: Not exactly one trailin
ENABLE_FIX=1

# Command for fixing
MY_FIX_CMD="aci-trailing-newline -1 \"\$1\" || ((echo \"\" >> \"\$1\" && sed -i\"\" -e :a -e \"/^\n*\\\$/{\\\$d;N;ba\" -e \"}\" \"\$1\") && echo \"Fixing: \$1\" || echo \"FAILED: \$1\")"
MY_FIX_CMD="aci-trailing-newline -1 \"\$1\" || ((echo \"\" >> \"\$1\" && (TMP_FILE=\$(mktemp); sed -e :a -e \"/^\n*\\\$/{\\\$d;N;ba\" -e \"}\" \"\$1\" > \${TMP_FILE} && mv \${TMP_FILE} \"\$1\"; ec=\$?; rm -f \"\${TMP_FILE}\"; exit \$ec)) && echo \"Fixing: \$1\" || echo \"FAILED: \$1\")"

# Command to be displayed for --info
MY_INFO="aci-trailing-newline -v"
Expand Down Expand Up @@ -907,6 +907,18 @@ if [ "${MY_LST}" = "1" ]; then
fi


if [ "${MY_FIX}" = "1" ]; then
printf "%s\n" "${output}"

if [[ $output =~ ^FAILED\s: ]]; then
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
exit 1
else
printf "${CLR_SUC}[OK] %s${CLR_CLS}\n" "${MY_FINISH_OK}"
exit 0
fi
fi

if [ "${output}" != "" ]; then
printf "%s\n" "${output}"
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
Expand Down
14 changes: 13 additions & 1 deletion bin/file-trailing-space
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ MY_CHECK="LC_ALL=C grep --color=always -inHE \"${MY_REG}\" \"\$1\" || true"
ENABLE_FIX=1

# Command for fixing
MY_FIX_CMD="grep --color=always -iqE \"${MY_REG}\" \"\$1\" && (sed -i\"\" \"s/[[:blank:]]*\$//\" \"\$1\" && echo \"Fixing: \$1\" || echo \"FAILED: \$1\") || true"
MY_FIX_CMD="grep --color=always -iqE \"${MY_REG}\" \"\$1\" && ((TMP_FILE=\$(mktemp); sed \"s/[[:blank:]]*\$//\" \"\$1\" > \"\${TMP_FILE}\" && mv \"\${TMP_FILE}\" \"\$1\"; ec=\$?; rm -f \"\${TMP_FILE}\"; exit \$ec) && echo \"Fixing: \$1\" || echo \"FAILED: \$1\") || true"

# Command to be displayed for --info
MY_INFO="grep -V | grep -E '([0-9]+\.+)+'"
Expand Down Expand Up @@ -907,6 +907,18 @@ if [ "${MY_LST}" = "1" ]; then
fi


if [ "${MY_FIX}" = "1" ]; then
printf "%s\n" "${output}"

if [[ $output =~ ^FAILED\s: ]]; then
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
exit 1
else
printf "${CLR_SUC}[OK] %s${CLR_CLS}\n" "${MY_FINISH_OK}"
exit 0
fi
fi

if [ "${output}" != "" ]; then
printf "%s\n" "${output}"
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
Expand Down
12 changes: 12 additions & 0 deletions bin/file-utf8
Original file line number Diff line number Diff line change
Expand Up @@ -906,6 +906,18 @@ if [ "${MY_LST}" = "1" ]; then
fi


if [ "${MY_FIX}" = "1" ]; then
printf "%s\n" "${output}"

if [[ $output =~ ^FAILED\s: ]]; then
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
exit 1
else
printf "${CLR_SUC}[OK] %s${CLR_CLS}\n" "${MY_FINISH_OK}"
exit 0
fi
fi

if [ "${output}" != "" ]; then
printf "%s\n" "${output}"
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
Expand Down
15 changes: 14 additions & 1 deletion bin/file-utf8-bom
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ MY_CHECK="awk \"/^\xEF\xBB\xBF/ {print FILENAME} {nextfile}\" \"\$1\" || true"
ENABLE_FIX=1

# Command for fixing
MY_FIX_CMD="out=\"\$( awk \"/^\xEF\xBB\xBF/ {print FILENAME} {nextfile}\" \"\$1\" )\" || true; if [ \"\${out}\" != \"\" ]; then (sed -i\"\" -e \"1s/^\xEF\xBB\xBF//\" \"\$1\" && echo \"Fixing: \$1\" || echo \"FAILED: \$1\"); fi"
TMP_FILE=$(mktemp)
MY_FIX_CMD="out=\"\$( awk \"/^\xEF\xBB\xBF/ {print FILENAME} {nextfile}\" \"\$1\" )\" || true; if [ \"\${out}\" != \"\" ]; then (sed -e \"1s/^\xEF\xBB\xBF//\" \"\$1\" > "${TMP_FILE}" && mv "${TMP_FILE}" \"\$1\" && echo \"Fixing: \$1\" || echo \"FAILED: \$1\"); fi"

# Command to be displayed for --info
MY_INFO="(awk -Wversion 2>/dev/null || awk --version) | grep -E '(([0-9]+)(\.))+'"
Expand Down Expand Up @@ -907,6 +908,18 @@ if [ "${MY_LST}" = "1" ]; then
fi


if [ "${MY_FIX}" = "1" ]; then
printf "%s\n" "${output}"

if [[ $output =~ ^FAILED\s: ]]; then
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
exit 1
else
printf "${CLR_SUC}[OK] %s${CLR_CLS}\n" "${MY_FINISH_OK}"
exit 0
fi
fi

if [ "${output}" != "" ]; then
printf "%s\n" "${output}"
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
Expand Down
12 changes: 12 additions & 0 deletions bin/git-conflicts
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,18 @@ if [ "${MY_LST}" = "1" ]; then
fi


if [ "${MY_FIX}" = "1" ]; then
printf "%s\n" "${output}"

if [[ $output =~ ^FAILED\s: ]]; then
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
exit 1
else
printf "${CLR_SUC}[OK] %s${CLR_CLS}\n" "${MY_FINISH_OK}"
exit 0
fi
fi

if [ "${output}" != "" ]; then
printf "%s\n" "${output}"
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
Expand Down
12 changes: 12 additions & 0 deletions bin/git-ignored
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,18 @@ if [ "${MY_LST}" = "1" ]; then
fi


if [ "${MY_FIX}" = "1" ]; then
printf "%s\n" "${output}"

if [[ $output =~ ^FAILED\s: ]]; then
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
exit 1
else
printf "${CLR_SUC}[OK] %s${CLR_CLS}\n" "${MY_FINISH_OK}"
exit 0
fi
fi

if [ "${output}" != "" ]; then
printf "%s\n" "${output}"
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
Expand Down
12 changes: 12 additions & 0 deletions bin/inline-css
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,18 @@ if [ "${MY_LST}" = "1" ]; then
fi


if [ "${MY_FIX}" = "1" ]; then
printf "%s\n" "${output}"

if [[ $output =~ ^FAILED\s: ]]; then
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
exit 1
else
printf "${CLR_SUC}[OK] %s${CLR_CLS}\n" "${MY_FINISH_OK}"
exit 0
fi
fi

if [ "${output}" != "" ]; then
printf "%s\n" "${output}"
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
Expand Down
12 changes: 12 additions & 0 deletions bin/inline-js
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,18 @@ if [ "${MY_LST}" = "1" ]; then
fi


if [ "${MY_FIX}" = "1" ]; then
printf "%s\n" "${output}"

if [[ $output =~ ^FAILED\s: ]]; then
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
exit 1
else
printf "${CLR_SUC}[OK] %s${CLR_CLS}\n" "${MY_FINISH_OK}"
exit 0
fi
fi

if [ "${output}" != "" ]; then
printf "%s\n" "${output}"
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
Expand Down
12 changes: 12 additions & 0 deletions bin/regex-grep
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,18 @@ if [ "${MY_LST}" = "1" ]; then
fi


if [ "${MY_FIX}" = "1" ]; then
printf "%s\n" "${output}"

if [[ $output =~ ^FAILED\s: ]]; then
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
exit 1
else
printf "${CLR_SUC}[OK] %s${CLR_CLS}\n" "${MY_FINISH_OK}"
exit 0
fi
fi

if [ "${output}" != "" ]; then
printf "%s\n" "${output}"
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
Expand Down
12 changes: 12 additions & 0 deletions bin/regex-grep-negative
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,18 @@ if [ "${MY_LST}" = "1" ]; then
fi


if [ "${MY_FIX}" = "1" ]; then
printf "%s\n" "${output}"

if [[ $output =~ ^FAILED\s: ]]; then
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
exit 1
else
printf "${CLR_SUC}[OK] %s${CLR_CLS}\n" "${MY_FINISH_OK}"
exit 0
fi
fi

if [ "${output}" != "" ]; then
printf "%s\n" "${output}"
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
Expand Down
12 changes: 12 additions & 0 deletions bin/regex-perl
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,18 @@ if [ "${MY_LST}" = "1" ]; then
fi


if [ "${MY_FIX}" = "1" ]; then
printf "%s\n" "${output}"

if [[ $output =~ ^FAILED\s: ]]; then
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
exit 1
else
printf "${CLR_SUC}[OK] %s${CLR_CLS}\n" "${MY_FINISH_OK}"
exit 0
fi
fi

if [ "${output}" != "" ]; then
printf "%s\n" "${output}"
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
Expand Down
12 changes: 12 additions & 0 deletions bin/syntax-bash
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,18 @@ if [ "${MY_LST}" = "1" ]; then
fi


if [ "${MY_FIX}" = "1" ]; then
printf "%s\n" "${output}"

if [[ $output =~ ^FAILED\s: ]]; then
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
exit 1
else
printf "${CLR_SUC}[OK] %s${CLR_CLS}\n" "${MY_FINISH_OK}"
exit 0
fi
fi

if [ "${output}" != "" ]; then
printf "%s\n" "${output}"
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
Expand Down
12 changes: 12 additions & 0 deletions bin/syntax-css
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,18 @@ if [ "${MY_LST}" = "1" ]; then
fi


if [ "${MY_FIX}" = "1" ]; then
printf "%s\n" "${output}"

if [[ $output =~ ^FAILED\s: ]]; then
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
exit 1
else
printf "${CLR_SUC}[OK] %s${CLR_CLS}\n" "${MY_FINISH_OK}"
exit 0
fi
fi

if [ "${output}" != "" ]; then
printf "%s\n" "${output}"
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
Expand Down
12 changes: 12 additions & 0 deletions bin/syntax-js
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,18 @@ if [ "${MY_LST}" = "1" ]; then
fi


if [ "${MY_FIX}" = "1" ]; then
printf "%s\n" "${output}"

if [[ $output =~ ^FAILED\s: ]]; then
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
exit 1
else
printf "${CLR_SUC}[OK] %s${CLR_CLS}\n" "${MY_FINISH_OK}"
exit 0
fi
fi

if [ "${output}" != "" ]; then
printf "%s\n" "${output}"
printf "${CLR_ERR}[ERR] %s${CLR_CLS}\n" "${MY_FINISH_ERR}"
Expand Down
Loading