Skip to content

Instantly share code, notes, and snippets.

@harishgonnabattula
Created August 25, 2018 00:44
Show Gist options
  • Save harishgonnabattula/68371af2f6ddce65b5d1071082276925 to your computer and use it in GitHub Desktop.
Save harishgonnabattula/68371af2f6ddce65b5d1071082276925 to your computer and use it in GitHub Desktop.
Bash script to organize files in a Xcode project directory into MVVM structure. Uses the naming convention to do this.
echo "Welcome to Automatic MVVM organizer. Here pop a champange 🍾🍾🍾"
path=""
read -p "Enter your XCode project directory: " path
cd $path
if [ ! -d "./Controllers" ]
then
mkdir "Controllers"
fi
if [ ! -d "./ViewModels" ]
then
mkdir "ViewModels"
fi
if [ ! -d "./Views" ]
then
mkdir "Views"
fi
if [ ! -d "./Models" ]
then
mkdir "Models"
fi
controllers=$(ls | grep "[A-Za-z]*Controller.swift")
viewModels=$(ls | grep "[A-Za-z]*ViewModel.swift")
view=$(ls | grep "[A-Za-z]*View.swift")
models=$(ls | grep "[A-Za-z]*[^View]Model.swift")
if [[ "$controllers" ]]
then
while read -r line; do
mv $line "./Controllers" > /dev/null;true
done <<< "$controllers"
fi
if [[ "$viewModels" ]]
then
while read -r line; do
mv $line "./ViewModels" > /dev/null;true
done <<< "$viewModels"
fi
if [[ "$view" ]]
then
while read -r line; do
mv $line "./Views" > /dev/null;true
done <<< "$view"
fi
if [[ "$models" ]]
then
while read -r line; do
mv $line "./Models" > /dev/null;true
done <<< "$models"
fi
echo "Done!!!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment