How to run a command when atom starts

被刻印的时光 ゝ 提交于 2020-01-15 03:53:26

问题


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.

I know init.coffee is run when Atom starts, but I don't know how to run a command from there.


回答1:


I finally found the answer here:

atom.commands.dispatch(atom.views.getView(atom.workspace), 'package:command');

Just change package:command to your desired package & command, and put the result in your init.coffee.

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) 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()).

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)}


来源:https://stackoverflow.com/questions/41645238/how-to-run-a-command-when-atom-starts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!