Created

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Replaces all occurences of .bind(bind, args) with .pass(args, bind) in the target files or directories.

View replace-bind.sh
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
#!/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

spectacular

awesome

Thanks for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.