Package that's runs a cli command with the selected text as its first argument?


Hi community!

I’m interested if there is a package that let’s me run a cli command with the selected text?


I don’t know about any packages but you can accomplish this in your init script (~/.atom/ Consider the following example:

{BufferedProcess} = require 'atom'
atom.commands.add 'atom-text-editor', 'custom:execute-command-on-highlighted-text': ->
  selectedText = atom.workspace.getActiveTextEditor().getSelectedText()
  command = 'echo'
  args = [selectedText]
  options = {}
  output = ''
  stdout = (out) ->
    output += out
  exit = (code) ->
    if code isnt 0
      message = "'#{command}' failed to execute sucessfully!"
      options =
        detail: output
        dismissable: true
      atom.notifications.addError message, options
      message = "'#{command}' executed successfully!"
      options =
        detail: output
        dismissable: false
      atom.notifications.addSuccess message, options
  new BufferedProcess {command, args, options, stdout, exit}

This will pass the selected text in your active editor to the echo command and create a notification with its output.

Run local exe in atom

Nice, thanks for the answer


There are packages that claim to run selected code from many languages. You should request support for scripts. They may even have one already. I prefer packages over init code because they are supported.