Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I try to define a custom behaviour of the backward-kill-word function in bash xterm. For that, I need to catch the command line before validate it. For instances, if I type sdcds/edfdD sdf/sdf without typing enter, I want by using a shortcut like esc + backspace to catch the line sdcds/edfdD sdf/sdf in a temporary variable to apply a sed after. I have already written the sed and the bind command but I cannot find anywhere how to catch the buffer command line.

Update from Answer

Ok thanks a lot, I think I'm not clear enough in my explanation. What I want to do is to create a function and the related bind key in the bash.rc to modify the text in the command line. Imagine, I want to define a function which removes the command line (before typing enter) till "/" for example and only till /, I could write in my .bash.rc :

function backward-delete-to-slash () { echo $BUFFER_COMMAND_LINE | sed  's:\(.*[/][/]*).*:\1:';}

bind -x '"\e\d": backward-delete-to-slash'

My problem is to catch the command line into a $BUFFER_COMMAND_LINE variable. If I had this variable, I could do for instance :

$: sdffs/dsfd dsfsdf/dfdsf (without typing enter)

esc + backspace

$: sdffs/dsfd dsfsdf/

So I hope to be more exhaustive.

share|improve this question

migrated from stackoverflow.com Oct 25 '11 at 2:27

This question came from our site for professional and enthusiast programmers.

    
Please do not post answer to your question, use the edit button to add additional information to a question. Please review the FAQ since this is not a traditional forum –  Diago Oct 25 '11 at 13:47
add comment

1 Answer 1

If you know vi a bit, try this:

$ set -o vi
$ bind vi-yank-to '\ey'
$ type-your-text-here - then press Home to go to begin-of-line, esc-y

The line is in a buffer now. Press Ctrl-c to get a new line, then

$ sed something-and-then esc-p

The text from the buffer should appear.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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