Skip to content

Instantly share code, notes, and snippets.

@JayBazuzi
Created March 24, 2013 07:04
Show Gist options
  • Save JayBazuzi/5230866 to your computer and use it in GitHub Desktop.
Save JayBazuzi/5230866 to your computer and use it in GitHub Desktop.
Add a copyright header to the all your source files, with PowerShell.
# Create a file `~\header.cs` with the copyright or whatever you want
# in each file. Then run this script.
#
# Notes:
#
# Second step will force BOM at the start, and newline at the end, of each
# file. It will also push all file encodings to be the same. Those make
# diffs a little ugly.
#
# So, I do it in two steps: one to normalize encoding, and one to actually
# insert the header.
#
$encoding = "utf8" # change this if step 1 produces wacky, unexpected results results
$pattern = "*.cs" # files you want to change.
gci -Recurse -Include $pattern -File |
% {
cp $_.FullName ~/temp -Force
gc ~/temp | Out-File $_.FullName -Encoding $encoding
}
git gui # review, and commit
gci -Recurse -Include $pattern -File |
% {
cp $_.FullName ~/temp -Force
cat ~/header.cs | Out-File $_.FullName -Encoding $encoding
gc ~/temp | Out-File $_.FullName -Encoding $encoding -Append
}
git gui # review, and commit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment