当原子启动时如何运行命令 [英] How to run a command when atom starts

查看:47
本文介绍了当原子启动时如何运行命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在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 ToolsCtrl+Shift+IF12打开它).

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆