ios 如何从终端打开 Xcode?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28576238/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to open Xcode from terminal?
提问by user456543
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 compile -a MyApp a.xcodeproj
& open a.xcodeproj
but I'm not sure which one to use and neither works. I also added this to the bash file after suggestion $ alias xcode="open -a Xcode"
It still doesn't work. I need a path/terminal expert to help me configure a way to run Xcode from the terminal because I'm trying to use cocoa pods.
我注意到我当前的 bash 文件有export PATH=$PATH:/Applications/MAMP/library/bin
,我把它放在那里来设置对 mamp 的终端访问。我一直在尝试编译-a MyApp a.xcodeproj
&open a.xcodeproj
但我不确定要使用哪个,而且都不起作用。我还在建议后将$ alias xcode="open -a Xcode"
其添加到 bash 文件中,但仍然无效。我需要一个路径/终端专家来帮助我配置一种从终端运行 Xcode 的方法,因为我正在尝试使用可可豆荚。
回答by jaybuff
xed does this and ships with xcode. Run
xed 执行此操作并随 xcode 一起提供。跑
xed .
man xed
for more info.
man xed
了解更多信息。
回答by Arian Faurtosh
If open .xcodeproj
doesn't work, then you can use the following to force Xcode to open via terminal.
如果open .xcodeproj
不起作用,那么您可以使用以下命令强制 Xcode 通过终端打开。
Step 1.
第1步。
Open Terminal. I am assuming you know how to do this, because your question was how to open Xcode in the terminal.
打开终端。我假设您知道如何执行此操作,因为您的问题是如何在终端中打开 Xcode。
Step 2.
第2步。
Type the following line in terminal. This will open your .bash_profile
with vim
(a terminal text editor). The ~/
means that it will open it in your home directory. So your current location doesn't matter.
在终端中键入以下行。这将打开您.bash_profile
的vim
(终端文本编辑器)。这~/
意味着它将在您的主目录中打开它。所以你当前的位置并不重要。
vim ~/.bash_profile
Step 3.
第 3 步。
When using vim
you will need to go into insert mode, which basically means you can start typing into the file. To do this you will just need to hit the ikey.
使用时,vim
您需要进入插入模式,这基本上意味着您可以开始输入文件。要做到这一点,您只需要按一下i键。
i // <- this will get you into insert mode
Step 4.
第四步。
Then type the following on it's own line in .bash_profile
. This tells bash, to set an alias up, the alias's name will be xcode
, and the alias value will be open -a Xcode
. Make sure you do not have any spaces on the left or right of the equals sign (=
).
然后在.bash_profile
. 这告诉 bash,要设置别名,别名的名称将为xcode
,别名值为open -a Xcode
。确保等号 ( =
)的左侧或右侧没有任何空格。
alias xcode="open -a Xcode"
Step 5.
第 5 步。
Since we went into insert mode by using the ikey, you need to hit the ESCto exit insert mode. then hit the :wqreturnkey to escape, write, and quit.
由于我们使用i键进入插入模式,因此您需要ESC按 退出插入模式。然后:wqreturn按键退出、写入和退出。
ESC // <- this will exit insert mode
:wq // <- writes and quit the file
Step 6.
第 6 步。
This will need to reload your bash profile in bash, after making changes to it. The .
will basically run your .bash_profile
again.
在对它进行更改后,这将需要在 bash 中重新加载您的 bash 配置文件。在.
将基本运行.bash_profile
一次。
. ~/.bash_profile
Step 7.
第 7 步。
Using the alias.
使用别名。
Make sure you are in the same directory as the name.xcodeproj
, check this by using ls
. If you see it do the following:
确保您与 位于同一目录中name.xcodeproj
,请使用ls
. 如果您看到它,请执行以下操作:
xcode name.xcodeproj
obviously you want to replace name
with the file name
显然你想name
用文件名替换
回答by Audun Olsen
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.
旧线程,但我最近刚刚研究是否有办法自己从终端打开 Xcode,并且在发现过于冗长的$ open -a Xcode projname.xcodeproj
命令时并不满意。您可以像 Arian Faurtosh 的回答一样为命令的一半添加别名,但是如果您要编辑 bash 脚本,则函数可以为您提供更好的服务。
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.
将上面的代码保存到每个会话的 shell 源文件中。现在您可以使用$ xcode
它,只要您的当前目录包含一个 .xcodeproj 目录,它就会启动 Xcode。
回答by Jayprakash Dubey
You are in wrong directory. Consider 'a' folder on desktop that contains a.xcodeproj and other files. Navigate to 'a' directoryin terminal.
你在错误的目录中。考虑桌面上包含 a.xcodeproj 和其他文件的“a”文件夹。导航到终端中的“a”目录。
MACBOOK-Users: macbook$ cd Users/macbook/Desktop/a
Now, macbook$ open a.xcodeproj
on terminal.
This opens 'a' project in Xcode.
现在,macbook$ open a.xcodeproj
在终端上。这将在 Xcode 中打开“a”项目。
回答by John Pitts
Very simple:
很简单:
Get into the directory of the project; you can tell if your in the proper directory by typing "ls" (short for 'list') into terminal and if you see the .xcodeproj suffix on your project name then you're in the right spot.
进入项目目录;您可以通过在终端中键入“ls”(“list”的缩写)来判断您是否在正确的目录中,如果您在项目名称上看到 .xcodeproj 后缀,那么您就在正确的位置。
open projectname.xcodeproj
打开项目名称.xcodeproj
The project will then open into Xcode
然后该项目将打开到 Xcode
Shortcut: on a macbook you can many times type just the first letter or two of your projectname and if you hit 'tab' it will autocomplete it. So you could type the above code like this...
快捷方式:在 macbook 上,您可以多次输入项目名称的第一个或两个字母,如果您点击“tab”,它会自动完成它。所以你可以像这样输入上面的代码......
open pr[tab] then you'd see... open projectname then you'd type... open projectname.xc[tab] and it would finish that too to end up like this... open projectname.xcodeproj
打开 pr[tab] 然后你会看到...打开 projectname 然后你会输入...打开 projectname.xc[tab] 它也会完成它最终会像这样......打开 projectname.xcodeproj
回答by wataru
I think your current directory is wrong. Move to the directory which contains MyApp.xcodeproj file.
我认为您当前的目录是错误的。移动到包含 MyApp.xcodeproj 文件的目录。