Created
August 30, 2010 08:58
-
-
Save timwienk/557192 to your computer and use it in GitHub Desktop.
Replaces all occurences of .bind(bind, args) with .pass(args, bind) in the target files or directories.
This file contains hidden or 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
#!/bin/sh | |
usage(){ | |
echo 'Replaces all occurences of .bind(bind, args) with' | |
echo '.pass(args, bind) in the target files or directories.' | |
echo | |
echo "Usage: $0 [options] [paths...]" | |
echo | |
echo 'options:' | |
echo ' -h' | |
echo ' --help Show this help.' | |
echo ' -n' | |
echo " --dry-run Don't do anything, only show the files and lines" | |
echo ' that would be affected.' | |
echo | |
echo 'arguments:' | |
echo ' [paths] Files and/or directories to search and replace.' | |
echo ' Defaults to the current working directory.' | |
} | |
while true; do | |
case "$1" in | |
-h|--help) usage; exit;; | |
-n|--dry-run) DRYRUN=1; shift;; | |
-*) echo "Unknown option '$1', ignoring." >&2; shift;; | |
--) shift; break;; | |
*) break;; | |
esac | |
done | |
ARGS=$@ | |
if [ -z "$ARGS" ]; then | |
ARGS='./' | |
fi | |
FILES=`grep -lr 'bind([^,)]\+,' $ARGS` | |
if [ -z "$FILES" ]; then | |
echo 'No occurences of .bind(bind, args) found.' | |
exit 1 | |
fi | |
if [ -n "$DRYRUN" ]; then | |
for F in $FILES; do | |
echo "$F:" | |
grep -nr 'bind([^,)]\+,' "$F" | |
done | |
exit | |
fi | |
echo "Replacing in files:" | |
for F in $FILES; do | |
echo "- $F" | |
sed -i'.orig' 's/\.bind(\([^,]*\), *\([^)]*\))/\.pass(\2, \1)/g' "$F" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
awesome