当原子启动时如何运行命令 [英] How to run a command when atom starts
问题描述
我想在Atom启动时运行各种命令,以便它以我期望的状态打开,而不必每次都手动运行这些命令.
I would like to run various commands when Atom starts, so that it opens in the state I expect it to without having to run those commands manually every time.
我知道init.coffee
是在Atom启动时运行的,但是我不知道如何从那里运行命令.
I know init.coffee
is run when Atom starts, but I don't know how to run a command from there.
推荐答案
我终于找到了答案此处:
atom.commands.dispatch(atom.views.getView(atom.workspace), 'package:command');
只需将package:command
更改为所需的包&命令,然后将结果放入您的init.coffee
.
Just change package:command
to your desired package & command, and put the result in your init.coffee
.
package:command
与您在keymap.cson
中使用的语法相同.基本上,它是程序包的名称和您可以在命令选项板中找到的命令的名称,但是使用小写字母并使用破折号而不是空格.例如:Fuzzy Finder: Toggle File Finder
变为fuzzy-finder:toggle-file-finder
package:command
is the same syntax you would use in keymap.cson
. Basically, it's the name of the package and the name of the command you can find in the command palette, but lowercased and using dashes instead of spaces. ex: Fuzzy Finder: Toggle File Finder
becomes fuzzy-finder:toggle-file-finder
atom.views.getView(atom.workspace)
用于将命令分派到整个工作区中.如果要定位当前的文本编辑器,请尝试atom.views.getView(atom.workspace.getActiveTextEditor())
.
atom.views.getView(atom.workspace)
is to dispatch the command into the full workspace. If you want to target the current text editor instead, try atom.views.getView(atom.workspace.getActiveTextEditor())
.
您可以通过在Dev Tools Console中运行它来测试整个事情(使用Window: Toggle Dev Tools
或Ctrl+Shift+I
或F12
打开它).
You can test the whole thing by running it in the Dev Tools Console (open it using Window: Toggle Dev Tools
, or Ctrl+Shift+I
, or F12
).
> atom.commands.dispatch(atom.views.getView(atom.workspace), 'fuzzy-finder:toggle-file-finder');
Promise {[[PromiseStatus]]: "resolved", [[PromiseValue]]: Array(1)}
这篇关于当原子启动时如何运行命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!