How to open Xcode from terminal?

前端 未结 6 1890
囚心锁ツ
囚心锁ツ 2021-01-30 05:04

I noticed my current bash file has export PATH=$PATH:/Applications/MAMP/library/bin which i put there to set up terminal access to mamp. I\'ve been trying to compi

6条回答
  •  死守一世寂寞
    2021-01-30 05:47

    Old thread, but I just recently researched if there's a way to open Xcode from the terminal myself, and was not satisfied when discovering the overly verbose $ open -a Xcode projname.xcodeproj command. You could alias half the command like Arian Faurtosh's answer, but if you're going to edit a bash script, a function can serve you much better.

    My solution:

    # Function to open Xcode projects from the command line, call with $ xcode
    function xcode {
    
      proj=$(ls -d *.xcodeproj/ 2>/dev/null)
    
      if [ -n "$proj" ]; then
        # Omit -beta if you're not using beta version
        open -a Xcode-beta "$proj"
      else
        echo "No Xcode project detected."
      fi
    
    }
    

    Save above code to whatever file your shell sources each session. Now you can use $ xcode and it will launch Xcode as long as your current directory contains a .xcodeproj dir.

提交回复
热议问题