Thursday, November 21, 2013

Batch PerlTidy a bunch of files all at once.

I've been doing a bit of perl development lately and do some tidying of the code before I commit my change set. To help with this process I came up with some short BASH one-liners:

Tidy all the perl files you have changed in a git branch:

>> git diff --name-only origin/master | egrep "\.pl$|\.pm$|\.t$" |  while read file; do echo "Tidying: $file"; perltidy -b $file; test -e "$file.bak" && { echo "Deleting $file.bak"; unlink "$file.bak"; } done;

Tidy all the perl file in a given directory:

>> find . -iname '*.pl' -iname '*.pm' -iname '*.t' |  while read file; 
do echo "Tidying: $file"; perltidy -b $file; test -e "$file.bak" && 
{ echo "Deleting $file.bak"; unlink "$file.bak"; } done;

No comments:

Post a Comment