├── LICENSE ├── README.md └── rename_xcode_project.sh /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 acefsm 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Super fast Xcode project renaming 3 | 4 | ![Alt Text](https://i.imgur.com/3q6Kp6N.gif) 5 | 6 | It should be executed from inside root of Xcode project directory and called with two string parameters: 7 | rename_xcode_project.sh **$OLD_PROJECT_NAME** & **$NEW_PROJECT_NAME** 8 | 9 | Script goes through all the files and directories recursively, including Xcode project or workspace file and replaces all occurrences of **$OLD_PROJECT_NAME** string with **$NEW_PROJECT_NAME** string (both in each file's name and content). 10 | 11 | ## Usage 12 | 13 | ```sh 14 | # download script and make it executable 15 | $ curl https://raw.githubusercontent.com/acefsm/rename_xcode_project/main/rename_xcode_project.sh -o rename_xcode_project.sh && chmod +x rename_xcode_project.sh 16 | 17 | # run script 18 | $ ./rename_xcode_project.sh "$OLD_PROJECT_NAME" "$NEW_PROJECT_NAME" 19 | 20 | # remove script 21 | $ rm rename_xcode_project.sh 22 | ``` 23 | 24 | ## Performance 25 | More than 150x (1️⃣5️⃣0️⃣) times faster than [swift version](https://github.com/appculture/xcode-project-renamer) 26 | | Project | Bash time | Swift time| 27 | | ------ | ------ | ------ | 28 | | Kickstarter | 1.2 seconds | 197 seconds | 29 | | RxSwift | 3 seconds | 17 seconds | 30 | 31 | ```sh 32 | # Bash version 33 | ./rename_xcode_project.sh Kickstarter Kukumber 0.59s user 0.56s system 94% cpu 1.211 total 34 | ./rename_xcode_project.sh Rx RXXX 1.04s user 1.79s system 92% cpu 3.065 total 35 | 36 | # Swift version 37 | ./rename.swift Kickstarter Kukumber 195.24s user 1.32s system 99% cpu 3:17.15 total 38 | ./rename.swift Rx RXXX 16.68s user 0.57s system 98% cpu 17.445 total 39 | 40 | ``` 41 | 42 | ## License 43 | This code is released under the MIT license. See [LICENSE](LICENSE) for details. 44 | 45 | -------------------------------------------------------------------------------- /rename_xcode_project.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | function replaceInFiles { 4 | sourceString=${1} 5 | targetString=${2} 6 | grep -rl "${sourceString}" --exclude-dir='.*/Carthage/Pods/fastlane/build' --exclude='.DS_Store' ./ | xargs -I{} sed -i \'\' "'s/$sourceString/$targetString/g'" {} 7 | } 8 | 9 | function usage() { 10 | echo >&2 "Usage: $0 OLD_PROJECT_NAME NEW_PROJECT_NAME" 11 | } 12 | 13 | if [[ $# -lt 2 ]]; then 14 | usage 15 | exit 1 16 | fi 17 | 18 | OLD_PROJECT_NAME=$1 19 | NEW_PROJECT_NAME=$2 20 | 21 | cNone='\033[00m' 22 | cRed='\033[00;31m' 23 | cGreen='\033[00;32m' 24 | cLightGreen='\033[01;32m' 25 | cCyan='\033[00;36m' 26 | cDarkGray='\033[00;90m' 27 | cWhite='\033[00;97m' 28 | 29 | function renameFilesAndDirectories { 30 | echo -e "${cLightGreen}Rename files and directories...${cNone}" 31 | SAVEIFS=$IFS 32 | IFS=$(echo -en "\n\b") 33 | for it in $(find . -depth ! -path "*/\.*" ! -path "*Pods*" ! -path "*Carthage*" ! -path "*fastlane*" ! -path "*build*" ! -path "*DS_Store*" -name "*${OLD_PROJECT_NAME}*") 34 | do 35 | beforeLastPath=${it%/*} 36 | lastPath=${it##*/} 37 | renamedLastPath=$(sed "s/$OLD_PROJECT_NAME/$NEW_PROJECT_NAME/g" <<< "$lastPath") 38 | newdir="$beforeLastPath/$renamedLastPath" 39 | echo -e " $cDarkGray$beforeLastPath/$cNone$lastPath $cNone-> $cGreen$renamedLastPath$cNone" 40 | mv "$it" "$newdir" 41 | done 42 | IFS=$SAVEIFS 43 | } 44 | 45 | function replaceContentsOfFiles { 46 | echo -e "${cLightGreen}Replace contents of files...${cNone}" 47 | SAVEIFS=$IFS 48 | IFS=$(echo -en "\n\b") 49 | for it in $(grep -RIl --exclude-dir={*Pods*,*Carthage*,.*,*build*,*fastlane*} --exclude={*DS_Store*,*.xcuserstate,*.png,*.jpg,*.json,*.appiconset,*.a,*.svg} ${OLD_PROJECT_NAME} *) 50 | do 51 | if [ -h "$it" ]; then 52 | continue 53 | fi 54 | beforeLastPath=${it%/*} 55 | lastPath=${it##*/} 56 | if [[ "$beforeLastPath" == "$lastPath" ]]; then 57 | echo -e " $lastPath" 58 | else 59 | echo -e " $cDarkGray$beforeLastPath/$cNone$lastPath" 60 | fi 61 | sed -i '' "s/$OLD_PROJECT_NAME/$NEW_PROJECT_NAME/g" "${it}" 62 | done 63 | IFS=$SAVEIFS 64 | 65 | } 66 | 67 | renameFilesAndDirectories 68 | replaceContentsOfFiles 69 | 70 | exit 0 71 | --------------------------------------------------------------------------------