0

Is there some way to make Terminal behave like "normal users" would consider normal text editing? For example, if I select/highlight some text command words/characters (before I press enter), I could paste some other text over top of the selected text? Or if I highlight some text and press delete, it deletes that text, not the text where the cursor is?

Or is there some other alternative app that is more graceful to use for command line operations?

1
  • 2
    In my mind this question is too ambiguous. Is it about command line interface or editing text files? What is defined as normal (only these two examples or more)? To the question: it's about shell, not Terminal. Shell, input, edit etc settings can be defined in respective rc files. Mar 28 at 7:25

4 Answers 4

3

You might want to take a look at Warp, which is a Terminal alternative app. One of its main selling points is:

Writing code in your terminal shouldn’t feel like 1978. Edit your commands like in a modern code editor with selections, cursor positioning, and completion menus.

I just tried selecting some text and pasting over it, and it works just as in a normal text editor.

Do make sure that you're OK with the privacy implications of the app before using it, though, as it needs a login to use. (See https://www.warp.dev/faq#why-is-login-required-for-a-terminal-app)

3
  • 1
    Warp does telemetry, it is not recommended. Mar 28 at 20:33
  • @MarcWilson And you can opt out of it if you wish: docs.warp.dev/getting-started/… Still, anyone who uses Warp has to make the decision of what they're comfortable with.
    – Lizzan
    Mar 29 at 6:54
  • 1
    Why should the user have to opt-out? The idea that a terminal needs telemetry is ridiculous. Mar 29 at 13:40
2

The nano editor can do this (included with macOS). To get nano to behave more like a GUI editor, you first enable “mouse support.”

Command Line

Enable mouse support by adding the -m flag.

nano -m foob.bar

Using .nanorc

Execute the following command to make mouse support persistent and you no longer have to add the -m flag every execution.

echo ‘set mouse’ >> ~/.nanorc

Bonus (unrelated) stuff

There are a few other settings I personally add to make nano just a bit better.

  • set autoindent. Automatically indents new lines to the same number of tabs/spaces of the previous line.
  • set suspend. Allows you to suspend nano to the background with a ^ Control Z shortcut. Useful if you have go back to the shell to check something
  • set tabsize 4 Sets the number of spaces to insert when you press the Tab key. Very useful for scripting languages
  • set const. Puts a cursor position indicator at the bottom of the screen, just above the menu. It’s extremely helpful for finding that exact position you need to be.

To add these settings, you can echo them in to the file as shown above, or simply use nano.

5
  • 1
    Is it .nanorc still even though the editor is pico? Neither man pico nor strings pico indicate any *rc being used.
    – nohillside
    Mar 28 at 5:54
  • 2
    Anyway, I think the OP was more looking at standard command entry into a shell, not at an editor.
    – nohillside
    Mar 28 at 5:56
  • @nohillside nano ≠ pico. There’s pico compatibility but it’s a separate thing. See nanorc for full details. As to the second, the Q can be read as either looking for a text editor or a terminal interface with text editor like interface (took me a couple reads). In that case, nano has the ability to execute commands and have output sent to the file buffer for editing.
    – Allan
    Mar 28 at 20:52
  • @Allan macOS no longer ships nano since nano is GPL3. Since Monterey, macOS ships UW Pico 5.09 with a symlink at /usr/bin/nano. The license for pico these days is the Apache License. Mar 28 at 21:08
  • Thanks for the update @MarcWilson. The Mac on location here is Catalina. However, the answer is still applicable if nano is installed via MacPorts/Homebrew
    – Allan
    Mar 28 at 21:20
2

Or is there some other alternative app that is more graceful to use for command line operations?

The alternative would be to use a fully-fledged text editor, like BBEdit, in which you can execute a document as a shell script, with the output in another window.

It also has a "Unix Worksheet" window, in which any command entered will be executed when you press Enter (as opposed to Return) or CTRL-Return at the end of it. enter image description here

You can then edit the command in the more usual GUI manner, and then re-execute the same line.

2

Most of the Bourne-compatible shells allow you to use ^X^E and open the current command line in your $EDITOR. ksh, bash, and zsh (shipped with macOS) all do. dash does not. I recommend that $EDITOR be a terminal editor you are comfortable with. If you do not set $EDITOR or $VISUAL, you will end up in vi (on macOS, vi is vim).

Save the file and exit the editor and it will be submitted to the shell as a command line.

The shell also supports a comprehensive suite of editor commands, make your choice between Emacs or Vi compatability.

You must log in to answer this question.

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