Friday, May 3, 2024
19
rated 0 times [  19] [ 0]  / answers: 1 / hits: 170871  / 3 Years ago, wed, august 25, 2021, 4:32:53

I am about to press enter to run a command in terminal, but before doing that, I want to copy the command to clipboard without using the mouse.



How?



If you're somewhere other than the terminal, Ctrl+Home does it.



Is there a way of arbitrarily selecting text like that in the terminal?



EDITED:




  • assume that using other programs like screen is not a good alternative

  • the text is to be pasted outside the terminal, so Ctrl+y and similar sequences do not solve it either


More From » command-line

 Answers
5

Bind following shortcut:



bind '"C-p": "C-eC-u xsel <<"EOF"
C-y
EOF
C-y"'


Now after using Crtl+P your line will be copied into clipboard. You can paste it in terminal using:



xsel


And into any X application using middle mouse button or Shift+Insert.


[#30951] Thursday, August 26, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
onomicsiberated

Total Points: 217
Total Questions: 98
Total Answers: 107

Location: Luxembourg
Member since Sun, May 28, 2023
1 Year ago
;