2

I used to use NEdit as a graphical text editor, but lately it no longer works right due to lack of maintenance. So I am looking for a replacement. Is there any graphical text editor that can send a selection of text directly to a shell command that is NOT defined in advance?

In NEdit, you select a chunk of text, tell it to filter it through a shell, and have a window come up where you enter the shell command (for example awk '{print $1}') and immediately get back the output of that command in the editor.

What other tool can be used to have the same functionality?

2
  • 3
    Im certain this can be done with vim, though I do not recall how to do it. Im not sure, if vim graphical enough? if not, there is Gvim, and Cream GUIs for vim.
    – j0h
    Sep 11, 2015 at 13:54
  • I suggest vim, vim has several "graphical" interfaces such as gvim and cream (there are alternates). See linux.com/learn/tutorials/…
    – Panther
    Sep 11, 2015 at 13:55

3 Answers 3

3

With gVim, select the text, type :! and the command you want. The selected lines will be replaced by the output of the command.

An example:

Editing /etc/apt/sources.list: enter image description here

Selected the text and pressed :! (the '<,'> in the command line is automatically added), with command awk '{print $3}': enter image description here

The text was replaced with the output: enter image description here

Of course, Vim's regex is powerful enough that I wouldn't use an external program (especially not sed, probably not awk) with it. Some care has to be taken with the commands - % with various suffixes is used to add information about the file (:!echo % prints the path of the file, for example), so you'll have to escape those.

Note that the :! command without a range (or selection) does not replace any lines. With selected text, the '<,'> is automatically added when you type : to enter the command line.

1
  • Hmm, thank you, that works. It's not entirely comfortable (vi(m) with it split command/edit mode isn't really intended as a GUI program) but it should be fine for quickly generating commands from some logs/output.
    – shodan
    Sep 14, 2015 at 12:49
1

Using Gedit :

Prerequisites:

  1. xclip, install from a terminal as sudo apt-get install xclip
  2. Gedit plugin External Tools. The goal of this plugin is to allow users to execute external commands from gedit interface.

To install the plugin, open gedit go to Edit -> Preferences -> Plugins -> External Tools.

enter image description here

Setup:

To configure the plugin, go to Tools -> Manage External Tools...

A dialog will appear.

  1. Add a new tool using the Add + button name it RunSelection
  2. Assign shortcut keys, here I have used Alt+J
  3. Change Edit, Save, Input, Output and Applicability as shown in the following screenshot.

enter image description here

How to run

  1. First select some text in gedit that you want to run in terminal.
  2. Run the external tool "RunSelection" you just set by hitting Alt+J on your keyboard or navigating to Tools -> External Tools

How it works

  1. When you select some text in gedit, it appears in X selections (clipboard).
  2. xclip -o makes the selection available to standard out and stores the value in a variable. (mcmd in above case)
  3. Finally the command is passed to gnome-terminal.
3
  • Hmm, not quite. This will execute a command selected in the editor and return the output. I need it to execute a command ON an selection of text and return the output.
    – shodan
    Sep 14, 2015 at 12:36
  • @shodan you can have several options in output. Just change "nothing" in output to your desired output. Or if you ask I can extend the script as your need. But clearly tell me where you want the output to appear.
    – sourav c.
    Sep 15, 2015 at 4:34
  • I'm not sure it is possible with external tools, to be honest. The workflow would be: Select some text. run plugin. Give plugin a command that would work in a shell, like awk '{print $2}'. Get the selection replaced by the output of the command you gave with the original selection as input. The point is that the command you are running needs to be given as parameter,not be defined statically.
    – shodan
    Sep 17, 2015 at 9:19
0

tl,dr NEdit (Nirvana Editor).

Versions:

  • Orginal version: NEdit, build/install from source or search your package manager (e.g. apt install nedit). This version has no unicode support
  • XNEdit: currently manatained, adds a couple of useful features to NEdit, like unicode support (I am using this, and it works like a charm). Build-install from source.
  • NEdit-ng: a Qt5 port of Nedit, with a couple of extra features.

Editors providing shell-filters integration

Even though this question is old, I ended up here every now and then because I was unsatisfied with text editors I used to use. I've tried quite many, and I feel I can add to the current answers. Here is a list of editors I tried that have support for shell filters (in one way or another). The list is not exhaustive, and I may edit it later to add more software.

Running in console

  • Gnu's nano: most likely already installed in your system (or try via package manager). Nano has great support to run shell commands: Ctrl+T and you get a prompt where you can write shell commands to be executed; you can choose to pipe the currently selected text to the command (prefix the command with the pipe operator |). The output of the command is inserted automatically (either appending to file or filtering selection). It is maybe less known that nano allows for user-defined keybindings, which makes it very convenient to work with it (you can basically add snippet functionality to it; I did it). man nano and man nanorc is everything you need to know.
  • Vi (or vim in compatibility mode): most of vi clones have the ability to run shell filter and/or shell commands to modify current text; in normal mode, press : and enter the command prompt. Here you can either type "ed" commands (powerful syntax, similar to 'sed' command) or prefixing the command with ! (or some other symbol/syntax) to read the output of a shell command. The integration with the shell is typically very good and straightfowrard, however more or less features may be provided according to the sèecific vi-clone you are using (e.g. searching for previous command history may not be possible).
  • Vim or Nvim: works as vi and has all features you would expect (e.g. command history).
  • micro: I never tried micro, but it should also have the ability to run shell filters/commands.

GUI programs

  • Geany: this is a great text editor. It has a good integration with the terminal, running an embedded VTE where you can interact with the terminal. It supports running and readig shell-commands output via snippets (which allow to define snippets that execute custom shell commands), and support shell filters on selected text or whole document/session via the "mini-script" plugin. However, the latter is a bit inconvenient to use, so if you plan to rely heavily on shell filters and commands you may be better served by another editor.

  • JetBrain IDEs: among modern, fully-featured IDEs, JetBrains's support shell filter via plugins. I found that Morgan Schweers's "Shell Process" provides the best experience. In my opinion, this works a little bit better than Geany's one, but still it is not good if you need to use a lot of shell filters.

  • Gedit supports shell filter/command via the "external tools" functionality. It works ok, but unfortunately it is a hassle to set up: basically, you need to define write a wrapper script (within Gedit) that calls any filter/script/command you defined previously. It is way too annoying in my opinion. You may want to use it in those rare occasions whene there is no other convenient option to achieve the editing you want if not using a custom script/filter.

  • Kate: I know Kate also offers integration with shell filters via plug-ins. However, I never tried it, so can't say anything about it.

  • XNEdit: among the others, XNEdit has by far the greatest support for shell filters and commands. It has predefined shortcuts to excute shell commands or filter text through a command/filter inserted in a pop-up dialog; it can write a shell command in the file being edited and it will execute it (reading its output) at a keypress. You can easily edit the editor's menu entries (guided by editor's GUI) to define new ones, executing arbitrary shell commands/filters with user-defined shortcuts and/or mouse right-click's menu. These entries may be grouped in submenus (for a more organized UI) and be available or not according to the filetype of the file being edited. The editor functionalities are greatly extended by the shell integration, making it extremely powerful; plus, it is super-easy to set up. It also has a macro language with few well-documented commands, that can be combined with arbitrary user-defined scripts to achieve basically anything. It also has a good (reasonably short) documentation and other extremely convenient integrations (like the xnc command and unique mouse-editing abilities).

Personal recommendation and opinions

When I found out about shell filters, I really tried hard to integrate them in my daily workflow: they are extremely convenient and give the user more editing-power than other software may achieve with complex and obscure plugins. Plus, shell filters work everywhare, in a standard, predictable way; you do not need to migrate your entire scrpts should you change software.

Before XNEdit, I struggled integrating filters in GUIs as I never found a painless workflow. So I would definitely recommend XNEdit for extensive use of filters/commands. It is an excellent piece of software, that can be used also when working on large projects. I personally substitued it to IDEs, and now I don't see myself coming back to them.

I also recommend to pair it with a console-editor, as this is typically needed for quick editing to file (especially if you work a lot with terminals and filters). For this, Nano is my pick. The only other reasonable alternative is vim (not vi), but it is unecessarly complex, non-standard, and you will end-up doing everything with plug-ins (rather than shell), reinventing the wheel (note POV: I've been using vim for 5 years as my only editor, and I was sold to it; but I changed my mind for the better).

Vi-clones are either buggy, or miss useful functionalities (e.g. syntax-highlighting, command history), or both. The best I've tried so far are Keith Bostic's nvi, Neatvi and kyx0r's Nextvi.

IMHO, Nano is a great compromise between the simplicity of vi and complexity of vim. Once you learn how to use command line (Ctrl+T) and piping, it is extremely powerful (not as convenient as XNEdit though). Just to get a sense of what you can do, I was able to add REPL functionality (for interactive Python and R development) combining nano shortcuts' binding and custom shell-script (not anything fancy) and snippets ability (even though it is probably not worth-it). It is worth to read through man nano and man nanorc (the only documentation you will need; plus, in couple of hours you will master it) and add few custom shortucts (e.g. select-all, copy-paste to/from clipboard).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .