Skip to content

Instantly share code, notes, and snippets.

@MihailPreis
Created December 21, 2020 09:22
Show Gist options
  • Save MihailPreis/e2e257c66f80a0c1988ead6aab564704 to your computer and use it in GitHub Desktop.
Save MihailPreis/e2e257c66f80a0c1988ead6aab564704 to your computer and use it in GitHub Desktop.
Add this in your *rc file
open_in_xcode() {
xfile=$1
if [[ -d "$xfile" && ${xfile: -12} == ".xcworkspace" ]]; then
open -a Xcode.app "$xfile"
elif [[ -d "$xfile" && ${xfile: -12} == ".xcodeproj" ]]; then
open -a Xcode.app "$xfile"
else
echo "Find project file in current dir."
project_files=(
$(find . -type d -depth 1 -name "*.xcworkspace")
$(find . -type d -depth 2 -name "*.xcworkspace")
$(find . -type d -depth 1 -name "*.xcodeproj")
$(find . -type d -depth 2 -name "*.xcodeproj")
$(find . -type d -depth 3 -name "*.xcodeproj")
)
project_files=(${project_files[@]//project\.xcworkspace/})
if [[ -d "${project_files[1]}" ]]; then
echo "Open ${project_files[1]}"
open -a Xcode.app "${project_files[1]}"
fi
fi
}
alias xcode=open_in_xcode
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment