Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
bash / console hotkeys for copy and paste
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Desktop Environments
View previous topic :: View next topic  
Author Message
felicehome
Apprentice
Apprentice


Joined: 30 Sep 2004
Posts: 217

PostPosted: Mon Dec 05, 2005 3:35 pm    Post subject: bash / console hotkeys for copy and paste Reply with quote

Hi all,

well I know, if I want to copy text from bash or any other shell, I have to highlight the text and then I can use my middle-mouse-button to paste it elsewhere.

But I don't like to get my hands off the keyboard just to copy and paste. So my question is:

Are there any hotkeys for highlighting and then paste text in a console ?

Many thx

felice
Back to top
View user's profile Send private message
ekutay
l33t
l33t


Joined: 30 Mar 2005
Posts: 636
Location: Berlin

PostPosted: Mon Dec 05, 2005 7:02 pm    Post subject: Reply with quote

For insert you can use Shift + Insert, but highlight I don't know.
A workaround could be to configure klipper to take the current selection one can fetch with typical emacs key bindings like ALT+d or similar and then paste using the mentioned Shift-Insert, but this is probably a bit tricky.
_________________
-- erol
Back to top
View user's profile Send private message
felicehome
Apprentice
Apprentice


Joined: 30 Sep 2004
Posts: 217

PostPosted: Tue Dec 06, 2005 1:37 pm    Post subject: Reply with quote

hello,

thx for your reply. For some reason SHIFT-Insert doesnt work.
Back to top
View user's profile Send private message
ekutay
l33t
l33t


Joined: 30 Mar 2005
Posts: 636
Location: Berlin

PostPosted: Tue Dec 06, 2005 1:57 pm    Post subject: Reply with quote

but should work 8O

You must press shift and insert both at the same time.
_________________
-- erol
Back to top
View user's profile Send private message
felicehome
Apprentice
Apprentice


Joined: 30 Sep 2004
Posts: 217

PostPosted: Tue Dec 06, 2005 2:44 pm    Post subject: Reply with quote

yes I know, but it doesn't work. Maybe it has something to do with my german keyboard layout. I dont't know yet.

Thx
Back to top
View user's profile Send private message
Syque
Tux's lil' helper
Tux's lil' helper


Joined: 15 Aug 2004
Posts: 110

PostPosted: Tue Dec 06, 2005 3:45 pm    Post subject: Reply with quote

Shift-insert requires that the text be highlighted with the mouse first, but felicehome was asking for a keyboard only solution.

If you're looking to copy text on the current command line, Control-u will cut all text before the cursor, and Control-k will cut all text after the cursor. Then Control-y will paste it. There are also bash commands to cut 1 word, and some others as well.

Otherwise, you might try the screen program. If you're using a console in screen Control-a [ will allow you to move the cursor by the arrow keys. Then hit Enter to set the beginning of the region, move the cursor to the end point of the region to be copied, and hit Enter again. Then hit Control-a ] to paste your text.
Back to top
View user's profile Send private message
felicehome
Apprentice
Apprentice


Joined: 30 Sep 2004
Posts: 217

PostPosted: Tue Dec 06, 2005 4:08 pm    Post subject: Reply with quote

@ Syque
thx have found these commands just a minute ago thank you very much.
Bash is based on readline. So all hotkeys are the same as for the readline lib.
They can all be found in "man readline". Very Very interesting!! It is really worth a look. There are also hotkeys to change from emacs style hotkeys (default) to vi style hotkeys. I'm reading the manual for readline right now. And I'm pretty much amazed what can be done. I will write a short tutorial next weekend. For customizing and using hotkeys in bash.

cheers
Back to top
View user's profile Send private message
ekutay
l33t
l33t


Joined: 30 Mar 2005
Posts: 636
Location: Berlin

PostPosted: Wed Dec 07, 2005 10:49 am    Post subject: Reply with quote

ekutay wrote:
... fetch with typical emacs key bindings like ALT+d or similar and then paste ....
Yeah man, I mentioned that too, but it will not work between different windows. :( To accomplish this with several windows you would need an additional tool like klipper which is able to synchronize the different selection buffers (highlight selection and common copy selection).
:idea: Try ALT-y after CTRL-y to change to previous selections if you use emacs style or edit a while with emacs to see, that really many emacs keybindings will work. I often need this feature.
_________________
-- erol
Back to top
View user's profile Send private message
TheX
Guru
Guru


Joined: 31 Jul 2004
Posts: 349
Location: .de

PostPosted: Wed Dec 07, 2005 12:43 pm    Post subject: Reply with quote

To highlight text in the console you can use GPM .
Its the console-mouse-driver. Nice lil prog.
This highlightet text can be pastet even in other consoles.
Back to top
View user's profile Send private message
felicehome
Apprentice
Apprentice


Joined: 30 Sep 2004
Posts: 217

PostPosted: Wed Dec 07, 2005 3:11 pm    Post subject: Reply with quote

Thank you guys so much for your help so far!!

I still have some questions:

@TheX or others who knows GPM:

there isn't really much information on http://linux.schottelius.org/gpm/
Can you do that highlighting and pasting stuff also with hotkeys or only with the mouse ?


@ekutay or others who knows emacs:

there is a really annoying limitation in using bash with those ctrl-k ctrl-u ctrl-y.... hotkeys: you can only copy and paste (as you said within one console) and even worse for me: you can only copy and paste stuff directly located in your command line. Hard to explain what I mean. But let's say I do an "emerge -pv whatever" emerge replies e.g.: "[ebuild R ] whatever/whatever-1.2." Now I want to copy the string "whatever/whatever" for pasting it in "/etc/portage/package.keywords". This doesn't work though with these hotkeys, cause I can only copy and paste what I typed in the console myself. frustrating!

So I experimented a little with emacs shell mode (M-x shell). This gives me the ability to copy and paste everything I like to, but again with an other drawback. If I now want to do a reverse-history-search using ("Ctrl-r"). Emacs uses reverse-search for the whole buffer. Annoying! Is there a way to overcome those limitations? Something like "Shift-Ctrl-r" is now reverse history search ? Also other hotkeys are affected. For example browsing the history with up down-arrow-keys now just moves the cursor like in an normal emacs buffer. However there are substitutions for these keys in emacs-shell-mode. (M-n, M-p) or (C-Up, C-Down). Are there similar solutions for searching the history? Cause I use those two hotkeys for searching (C-s, C-r) quite a lot.



Maybe there are other solutions to get a fully keyboard driven console. Inclusive copy and paste? Am I right that highlighting text in a console and middle-mouse paste (or shift-ins) elsewhere. Is an X feature? Maybe X.org can be configured to highlight text with keyboard? Any suggestions and thoughts are really welcome.

thanx so far for all comments, especially ekutay

Greetings Felice
Back to top
View user's profile Send private message
hicksboson
n00b
n00b


Joined: 18 Oct 2004
Posts: 31
Location: Kiel, Germany

PostPosted: Wed Dec 07, 2005 5:34 pm    Post subject: Reply with quote

felicehome wrote:

there isn't really much information on http://linux.schottelius.org/gpm/
Can you do that highlighting and pasting stuff also with hotkeys or only with the mouse ?

gpm = General Purpose Mouse Manager
...so I would believe it's mouse only (but I don't know for shure)

felicehome wrote:

there is a really annoying limitation in using bash with those ctrl-k ctrl-u ctrl-y.... hotkeys: you can only copy and paste (as you said within one console) and even worse for me: ... I can only copy and paste what I typed in the console myself. frustrating!

Not realy a solution, but a workaround to get command output to a file is the command tee. This reads from standard input and writes it to a file and to standard output. (A tee is a T-peace - e.g. in a tube, so everthing that comes through the tee is split up in two directions)
Code:

command | tee file
# you can also redirect the output of tee as if it came from the original command
command | tee file | otherCommand
command | tee file > otherFile

Then you can open this file in your favorite editor and just copy and paste between this and any other file. For emerge you can set the PORT_LOGDIR variable in /etc/make.conf. That will log the output of portage commands in that directory. But like I said, only workaround (and not the best).
felicehome wrote:

Am I right that highlighting text in a console and middle-mouse paste (or shift-ins) elsewhere. Is an X feature? Maybe X.org can be configured to highlight text with keyboard? Any suggestions and thoughts are really welcome.

I think there is something about copy and paste shortcuts in the xterm manpage. Look for the *translations resource. If I remember right, I didn't understodd it realy, or it wasn't realy useful. But maybe I was wrong ;) . At least it would be limited to xterm.
Maybe it's an idea to have a look, if your window manager can do this. The DEs (kde, gnome ...) can do this for shure, but a lot of "low-level" window managers support user defined shortcuts, so maybe the one of your choice can be configured to have a keyboard only copy'n paste.
Back to top
View user's profile Send private message
ekutay
l33t
l33t


Joined: 30 Mar 2005
Posts: 636
Location: Berlin

PostPosted: Thu Dec 08, 2005 1:41 pm    Post subject: Reply with quote

felicehome wrote:

@ekutay or others who knows emacs:

there is a really annoying limitation in using bash with those ctrl-k ctrl-u ctrl-y.... hotkeys: you can only copy and paste (as you said within one console) and even worse for me: you can only copy and paste stuff directly located in your command line. Hard to explain what I mean. But let's say I do an "emerge -pv whatever" emerge replies e.g.: "[ebuild R ] whatever/whatever-1.2." Now
Yeah, you want to overload emacs bindings with emacs binding, I think there is no easy resolution.
In this case I would use awk to process the output of your command or the screen suggestion above by Syque.
An example for awk is
Code:
emerge -pv whatever | awk '/ebuild/ {print $4}' >> /etc/portage/package.keywords
but try it out first, to see whether it works :!:.
Code:
erol@ARILLIN:~ > emerge -pv less | awk '/ebuild/ {print $4}'
sys-apps/less-393

Regards
_________________
-- erol
Back to top
View user's profile Send private message
nephros
Advocate
Advocate


Joined: 07 Feb 2003
Posts: 2139
Location: Graz, Austria (Europe - no kangaroos.)

PostPosted: Thu Dec 08, 2005 2:51 pm    Post subject: Reply with quote

Another possibility would be -- once again -- GNU screen.

With that you can freely scroll back in the saved-lines buffer (with Ctrl-A ESC) and do blockwise (and other) selecting and yanking into the paste buffer of any text contained therein with vi-style movement and selection commands.

See man screen on selecting and marking, here's an excerpt:

Code:
     Marking:«
   The copy range is specified by setting two marks. The text between
   these marks will be highlighted. Press space to set the first or second
  mark respectively.
 Y and y used to mark one whole line or to mark from start of line.
 W marks exactly one word.


the buffered text can then be pasted with middle mouse button or Ctrl-Insert as usual.

HTH
_________________
Please put [SOLVED] in your topic if you are a moron.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Desktop Environments All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum