Eric Roller's blog

Thursday, April 20, 2017

Open Xcode from the Terminal

Quite often I find myself in the Terminal and want to open Xcode with the project in the current directory:

> open CurrentProject.xcodeproj

This works just fine, of course, but with the following alias (added to ~/.cshrc), I don’t need to know the name of the project, assuming there is always only one project in the current directory:

> alias xcode '\ls | grep xcodeproj | xargs open'
> xcode

N.B. The use of ‘\ls’ ignores the alias that I have for ‘ls’. Instead of “ls *.xcodeproj”, the pipe via grep avoids errors like “ls: No match.”.

P.S. Knowing the name of the project is actually not the problem; since there are multiple items named “Current*” or “CurrentProject*” in the same folder, the issue is that I can’t just type “open SHIFT+C<TAB><CR>” (where pressing TAB autocompletes the name); instead, I have to type: “open SHIFT+C<TAB>SHIFT+P<TAB>.x<TAB><CR>”.