运行 bash 当前选定行的命令

Run bash command for currently selected line

我希望能够点击 cmd-shift-r 这样的快捷方式,然后自动 运行 一个 bash 命令,比如 mix test test/turtle/api/v3_test.exs:72.

换句话说:mix test {FILE_ACTIVE}:{FILE_ACTIVE_LINE_NUMBER}

完成此任务的最佳方法是什么?有没有一个原子包可以处理这个或者我自己可以快速编写的东西?

谢谢!

有一种相当低保真的方法可以使用您的 init.coffee 通过转到 FileInit Script... 或选择 Application: Open Your Init Script 来加载它命令面板。

  1. 将以下内容添加到 init.coffee 的底部:

    atom.commands.add 'atom-text-editor',
      'custom:execute-this-test': ->
        if editor = atom.workspace.getActiveTextEditor()
          row = editor.getCursors()[0].getBufferRow() + 1
          path = editor.buffer.file.path
          {spawn} = require 'child_process'
          mix = spawn 'mix', ['test', "#{path}:#{row}"]
          mix.stderr.on 'data', (data) ->
            atom.notifications.addError data.toString()
          mix.stdout.on 'data', (data) ->
            atom.notifications.addInfo data.toString()
          mix.on 'exit', (code) ->
            atom.notifications.addInfo "Exited with Code #{code}"
    
  2. 使用 Ctrl-S 保存文件并使用 Ctrl[重新加载文本编辑器-Alt-R.

  3. Atom 重新启动后,在文件中找到要对其执行代码的行,然后使用 Ctrl-Shift[=39 打开命令面板=]-P 并搜索 Execute This Test.

您可能想要调整代码以减少它生成的输出量,但是以上内容可能足以让您入门。如果您想进一步优化工作流程,您可以 create a Keybinding.