Last active
December 4, 2018 02:14
-
-
Save RedL0tus/1f4e132556bc986ae0d0ac9cf97d3ed5 to your computer and use it in GitHub Desktop.
Let's replace f-words with blyat!
This file contains 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/bash | |
# Ayy blyat! | |
# Replace all f-words with "blyat". | |
# set -x; | |
declare -A WORDS; | |
WORDS=( ["fuck"]="blyat" | |
["fucK"]="blyaT" | |
["fuCK"]="blyAT" | |
["fuCk"]="blyAt" | |
["fUCK"]="bLYAT" | |
["fUCk"]="bLYAt" | |
["fUck"]="bLYat" | |
["fUcK"]="bLYaT" | |
["FUCK"]="BLYAT" | |
["FUCk"]="BLYAt" | |
["FUck"]="BLYat" | |
["FUcK"]="BLYaT" | |
["FuCK"]="BlyAT" | |
["FuCk"]="BlyAt" | |
["Fuck"]="Blyat" | |
["FucK"]="BlyaT" | |
) | |
TMPDIR="/tmp/blyat"; | |
# Usage info | |
if [ $# -lt 1 ]; then | |
echo ">>> No path given, quitting..." | |
echo ">>> Usage: ayy.sh <path1> [path2] [path3]" | |
exit 0; | |
else | |
echo ">>> Ayy!" | |
fi | |
# Generate sed pattern | |
PATTERN="" | |
for word in "${!WORDS[@]}"; do | |
PATTERN="$PATTERN s/$word/${WORDS[$word]}/g;" | |
done | |
echo ">>> sed pattern generated: $PATTERN" | |
# Create temp directory | |
if [ ! -d $TMPDIR ]; then | |
echo ">>> Creating temp directory..."; | |
mkdir $TMPDIR; | |
fi | |
# Ayy | |
echo ">>> Start!" | |
for path in $@; do | |
if [ -e $path ]; then | |
echo ">>> Ayy $path"; | |
BASENAME=$(basename $path); | |
REALPATH=$(realpath $path); | |
cp -R $REALPATH $TMPDIR/; | |
find $TMPDIR/$BASENAME -type f -exec sed -i -e "$PATTERN" {} \;; | |
pushd $TMPDIR > /dev/null; | |
ln -s $REALPATH $TMPDIR/$BASENAME-orig; | |
echo "# Generated by ayy.sh" > $BASENAME.patch; | |
diff -Naur $BASENAME-orig $BASENAME >> $BASENAME.patch; | |
unlink $BASENAME-orig; | |
popd > /dev/null; | |
cp -v $TMPDIR/$BASENAME.patch .; | |
else | |
echo ">>> $path not exsist, skipping..." | |
fi | |
done | |
# Clean up | |
echo ">>> Cleaning..."; | |
rm -Rf $TMPDIR; | |
exit 0; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment