Last active
February 10, 2020 00:18
-
-
Save henriquemoody/5331147 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# Usage: {script} DIRECTORY | |
# Find PHP's commented code and remove then. | |
# | |
# --help, -h Displays this help | |
# | |
# Report bugs to Henrique Moody <henriquemoody@gmail.com> | |
# | |
declare -r SCRIPT_NAME=$(basename ${0}) | |
_help() | |
{ | |
sed -E 's/^#\s?(.*)/\1/g' "${0}" | | |
sed -nE '/^Usage/,/^Report/p' | | |
sed "s/{script}/${SCRIPT_NAME}/g" | |
} | |
if [[ "${1}" == '--help' ]] || [[ "${1}" == '-h' ]]; then | |
_help | |
exit 0 | |
elif [[ -z "${1}" ]]; then | |
_help 1>&2 | |
exit 1 | |
elif [ ! -d "${1}" ]; then | |
echo "${SCRIPT_NAME}: \`${1}\` is not a valid directory" 1>&2 | |
exit 2 | |
fi | |
declare PATTERN='^ *(\/\/|#).*(.+).*;( *|\/\/.*)$' | |
declare DIRECTORY="${1}" | |
_find_files() | |
{ | |
egrep --color -Rn "${PATTERN}$" --include="*.php" "${DIRECTORY}" | | |
cut -d ':' -f '1' | | |
sort -u | |
} | |
_find_files | | |
while read filename; do | |
sed -Ei "/${PATTERN}/d" "${filename}" | |
done | |
echo "Finished!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment