Skip to content

Instantly share code, notes, and snippets.

@celian-rib
Last active September 15, 2021 07:59
Show Gist options
  • Save celian-rib/803c4ad1125a700788bece7c58d8b024 to your computer and use it in GitHub Desktop.
Save celian-rib/803c4ad1125a700788bece7c58d8b024 to your computer and use it in GitHub Desktop.
Add a custom text header to you code files
headerFile="header.txt"
fileExt=".java"
red=`tput setaf 1`
green=`tput setaf 2`
cyan=`tput setaf 6`
yellow=`tput setaf 3`
reset=`tput sgr0`
function main () {
echo "${cyan}----------------------------------------------------"
echo
echo "Header generator (Made by Célian Riboulet)"
echo
echo "----------------------------------------------------"
echo
echo "${cyan}Looking for $fileExt files :"
echo "${green}- Generate [g]"
echo "${red}- Clear [c]${reset}"
read input
if test "$input" = "g"; then
echo
echo
echo "${yellow}Adding this header to all $fileExt file in the project !"
cat $headerFile
echo
echo "${reset}Adding headers ..."
for file in $(find ./ -name "*$fileExt"); do
if test "$(cat $file | head -n 1)" = "$(cat header.txt | head -n 1)"; then
echo "${yellow}[!] Header already found in $file"
else
cat $headerFile | cat - $file > temp && mv temp $file
echo "${green}[OK] Adding in $file"
fi
done
elif test "$input" = "c"; then
echo "${yellow}Removing all headers ..."
headerSize=$(wc -l < $headerFile)
for file in $(find ./ -name "*$fileExt"); do
if test "$(cat $file | head -n 1)" = "$(cat header.txt | head -n 1)"; then
echo "$(tail -n +$headerSize $file)" > $file
echo "${green}[OK] Removing in $file"
else
echo "${yellow}[!] No header found in $file"
fi
done
else
echo
echo "${red}ERROR : unkown action..."
main
fi
}
main
echo
echo "${green}done !"
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment