bash 在不打开空白窗口的情况下从命令行打开 Sublime 项目
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17326970/
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
Opening a Sublime project from the command line without opening a blank window
提问by Elias Zamaria
I am trying to figure out how to open a Sublime Text project from the command line.
我想弄清楚如何从命令行打开 Sublime Text 项目。
If I type subl foo.projectfor a project that is not open, it opens the project. But if I do this for a project that is already open, it opens a blank window for some reason. I have no idea whether this is a bug or intended behavior.
如果我输入subl foo.project一个未打开的项目,它会打开该项目。但是,如果我为已经打开的项目执行此操作,它会出于某种原因打开一个空白窗口。我不知道这是一个错误还是预期的行为。
Is it possible to come up with a command or shell script that takes a project filename, and opens it if it is not open, but focuses it if it is open? If so, how can I do this?
是否有可能想出一个命令或 shell 脚本,它接受一个项目文件名,如果它没有打开就打开它,但如果它打开则聚焦它?如果是这样,我该怎么做?
I am using Sublime Text 2.0.1 and OS X 10.8.4. I have sublsymlinked to /Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl.
我正在使用 Sublime Text 2.0.1 和 OS X 10.8.4。我已经subl符号链接到/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl.
I found this post on UserEchoand this post on the forumbut there haven't been any meaningful responses. Other than that, I haven't found anything else about this bug.
我发现这个职位上UserEcho和这个职位上的论坛,但再也没有出现过任何有意义的回应。除此之外,我还没有发现有关此错误的任何其他信息。
EDIT:I updated to the Sublime Text 3 beta and I still experience this bug. I haven't found a fix or workaround.
编辑:我更新到 Sublime Text 3 测试版,但我仍然遇到这个错误。我还没有找到修复或解决方法。
回答by JcKelley
This is a knownbug in Sublime Text 2/3 on OSX. The Developers have not made many comments about it, so it might not be something they're working on in the near future.
这是OSX 上 Sublime Text 2/3 中的一个已知错误。开发人员尚未对此发表太多评论,因此他们可能不会在不久的将来致力于此。
As for the bash script, you might want to head over to 'Ask Ubuntu'. Lot's of Unix gurus over there who might have a quick fix for you.
至于 bash 脚本,您可能想要转到“询问 Ubuntu”。那里有很多 Unix 专家,他们可能会为您提供快速解决方案。
回答by Gregory Vincic
I'm using this combination to switch between projects
我正在使用这种组合在项目之间切换
alias sp='subl --command "close_project"; subl --project'
sp myproject.sublime-project
Sometimes though the empty window still appears, then I think you may need a delay
有时虽然仍然出现空窗口,但我认为您可能需要延迟
alias sp='subl --command "close_project"; sleep 0.2; subl --project'
回答by thomaspaulb
It is a bug, still present in my build 3059. A workaround is to wait until the Sublime window is open, and then open the file.
这是一个错误,仍然存在于我的 build 3059 中。解决方法是等到 Sublime 窗口打开,然后打开文件。
Eg. put the following in your .bash_profile:
例如。将以下内容放入您的.bash_profile:
alias edit='subl && sleep 0.1 && subl'
(And don't forget to run source .bash_profileto refresh.) On my computer 0.1 seconds was quick enough, but it can be that this value has to be bigger on slower computers.
(并且不要忘记运行source .bash_profile以刷新。)在我的计算机上 0.1 秒已经足够快,但是在较慢的计算机上这个值可能必须更大。
回答by MattDMo
I'm not at my Mac at the moment to test it, but try playing with the "open_files_in_new_window"and/or "create_window_at_startup"settings in your Packages/User/Preferences.sublime-settingsfile. If this behavior isn't a bug on OSX, one or both of those settings should fix it.
我现在不在我的 Mac 上测试它,但尝试使用"open_files_in_new_window"和/或文件中的"create_window_at_startup"设置Packages/User/Preferences.sublime-settings。如果此行为不是 OSX 上的错误,则这些设置中的一个或两个都应该修复它。
回答by bideowego
I experienced a similar issue where the sublcommand would onlyopen blank windows, very annoying. I posted a fix on the Github issue here.
我遇到了类似的问题,该subl命令只会打开空白窗口,非常烦人。我在这里发布了关于 Github 问题的修复程序。
Here it is:
这里是:
If anyone experiences this issue and can't get the sublcommand to stop opening blank windows I solved it with the following steps:
如果有人遇到这个问题并且无法获得subl停止打开空白窗口的命令,我通过以下步骤解决了这个问题:
- Copy your "User Settings" into a file (you'll need to paste them in later)
- Locate your data folder as described here
- Move that data folder to a place you can still access it but not in the default location
- Quit Sublime Text
- Open Sublime Text
- (At this point your
sublcommand should work, you just need to restore your settings/packages etc...) - You should see that Sublime Text now created a new folder where the old one was
- Replace the
Installed Packages,LocalandPackagesfolders in the newfolder with those of the oldone - Paste your "User Settings" back into the JSON file for your user settings
- Quit Sublime Text and restart and you should now have your old settings back
- 将您的“用户设置”复制到一个文件中(稍后您需要将其粘贴)
- 按照此处所述找到您的数据文件夹
- 将该数据文件夹移动到您仍然可以访问但不在默认位置的位置
- 退出 Sublime Text
- 打开 Sublime 文本
- (此时你的
subl命令应该可以工作,你只需要恢复你的设置/包等......) - 您应该看到 Sublime Text 现在创建了一个新文件夹,旧文件夹所在的位置
- 更换
Installed Packages,Local并Packages在文件夹中新与那些文件夹老一个 - 将您的“用户设置”粘贴回用户设置的 JSON 文件中
- 退出 Sublime Text 并重新启动,您现在应该恢复旧设置
I hope this helps
我希望这有帮助

