12

It seems like a typical way that you have some output in the terminal and if you want to select certain phrase you use your mouse to copy it, but is there any way to select without using mouse? For example, I input ls, and get a list of files, and I want to select the second file (second row), is there a way to copy the name without using mouse?

1
10

Using tmux:

I use tmux in vi mode:

  1. Go to copy mode (in my config Prefix+escape, Default Prefix is Ctrl+b)
    • In config file (~/.tmux.conf): bind Escape copy-mode
  2. Move around (Using arrows)
  3. Select your desire output (Start selection with Space)
    • In my config v: bind-key -T copy-mode-vi y send-keys -X begin-selection
  4. Press Enter to copy the text.
    • In my config y: bind-key -T copy-mode-vi y send-keys -X copy-selection
  5. Press Prefix+p to Paste.

enter image description here

Also create a key binding like this:

bind C-c run "tmux save-buffer - | xsel -bi"

So you can save the buffer into system clipboard by pressing Prefix+Ctrl+c.

I have add my configuration cause it's more like vim than default config.


Using commands:

Here is what I do:

  1. Run the command (eg: ls -1)
  2. Process the output to get my desired result
  3. Pip it to xsel -bi

In your example:

$ ls -1 | sed -n 2p | xsel -bi
  • ls -1 prints the outputs each in one line
  • sed -n 2p get the second line
  • xsel has been used to copy the final result in clipboard.

If the command takes too long to run, first save the output to a file the process the output:

command > output
head -10 output | whatever | xsel -bi
0
0

The most common Linux terminals emulators cannot do this directly. There a 2 ones I am aware of, though.

One which exists for quite some time is Termite. It is rather spartanic, though (keyboard shortcuts not configurable, no multiple tabs).

Now there is a second one, which has these features named Mantid (which I' shamelessly advertising here :) ):

https://github.com/omgold/mantid-term

There isn't an Ubuntu build, yet, though, one Arch and RPM. You might try to build an RPM and convert to to deb using Alien, though.

2
  • I would like to try mantid, but I can not find any tutorial or manual. Is there any documentation out there? It would be good to know at least how it accomplishes the functionality requested in the question. Aug 8 '19 at 10:08
  • There is a manpage ('man mantid') and there are example configuration files in /usr/share/mantid. The manpage mostly documents the configuration options, and the active keybindings can be looked up in the config file.
    – omgold
    Aug 9 '19 at 11:05

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.