Skip to content

Instantly share code, notes, and snippets.

@chchrn
Last active December 3, 2020 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chchrn/8ed1cf3ee02825310f23adf47a9d8310 to your computer and use it in GitHub Desktop.
Save chchrn/8ed1cf3ee02825310f23adf47a9d8310 to your computer and use it in GitHub Desktop.
changeImportToAnglesForLib.sh
#!/bin/bash
# sample use:
thisScriptName=`basename "$0"`
if [[ $# -ne 3 ]]; then
echo "$thisScriptName <LIB PATH> <CODE PATH> <LIB NAME> \n"
echo "$thisScriptName ./myProject/src/Frameworks/ ./myProject/src Wlib \n"
exit 2
fi
libPath=$1
codePath=$2
libName=$3
libFileNames=( $(find $libPath -name "*.h" | sed 's!.*/!!') )
for libFileName in "${libFileNames[@]}"
do
importStr="#import \"${libFileName}\""
newImportStr="#import <${libName}\/${libFileName}>"
echo "Find imports of ${importStr}"
#files=( $(grep -include=\*.{h,m} -rl '$codePath' -e '#import "$fileName"') )
files=( $(grep --exclude-dir=$libPath -rl "${codePath}" -e "${importStr}"))
echo $files
for codeFilePath in "${files[@]}"
do
sed -i '' "s/${importStr}/${newImportStr}/g" $codeFilePath
echo "Changed $codeFilePath"
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment