1

I run fish (in gnome-terminal) with a custom style that gives me information about the current Git repository:

enter image description here

That's all very fine, but when I want to copy-paste some command with its output like so:

enter image description here

I want to get

$ du -sh . 
1012K   .

instead of

$ du -sh .            0⚹  0↺  0🗴 0≡   🜉 master 
1012K   .

Another use case would be copying from editors like vim with line numbers enabled -- a major pain in the behind.

Is there any way to prevent selection/copy of certain characters in a terminal?


FWIW, I'm aware that some styles move the caret to the next line:

<gutter left>           <gutter right>
$ <caret>

While a functional workaround, this is not what I'm asking for.

1

1 Answer 1

1

No, this is not possible with the command and its output. The terminal emulator copies whatever is onscreen. You need to copy-paste in two steps: once for the command and once for its output. A terminal could make it easier by allowing to select a non-contiguous region of text, like Firefox does on Ctrl+click, but I'm not aware of any terminal implementing this.

As for text editors and line numbers, this is still not possible as long as it's the terminal emulator that copies the text. However, here it might make more sense to use the copying feature of the editor itself (via keyboard or mouse). The editor could not only skip the line number, but also include parts of the text that are chopped at the right margin, preserve TAB characters, preserve other non-printable control characters etc.

10
  • That doesn't sound promising. That said, I just noticed that in some "GUI" terminal applications such as aptitude and htop, you can't select any text. Is that because they are redrawn continously, or do they capture mouse events somehow? Could e.g. fish hack the area through the terminal emulator? (Maybe this is not the best place for such a conversation.)
    – Raphael
    May 3, 2019 at 13:57
  • 1
    Aptitude and htop capture mouse events themselves. You can still select using Shift+mouse in most terminals.
    – egmont
    May 3, 2019 at 17:08
  • "Could e.g. fish hack the area through the terminal emulator?" Not really. Whether mouse is captured is global for the entire terminal at a time, not specific to some area. It could capture mouse events when you're editing a command line, but not when a command (e.g. "sleep 10") is running. And it could only select under its own area (the prompt and the command being edited) because it's unaware of the rest of the text. It probably couldn't even work on its previous prompts and command lines because it would be unaware of their vertical positioning. So no, forget this.
    – egmont
    May 3, 2019 at 17:12
  • I see, how unfortunate. Thanks! I guess the only alternative are HTML/JS terminal emulators then... :/
    – Raphael
    May 12, 2019 at 18:38
  • How would HTML/JS terminal emulators help you here?
    – egmont
    May 12, 2019 at 20:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.