3

I'm trying to create a keyboard shortcut to reset the current terminal. I'm using a .inputrc entry like this:

"\C-K": 'echo -en "\\033c"\n'

It works, however, I can't do that while typing a command.

For instance, if I'm typing a command like this (with the cursor at the end):

$ foobar

and press CTRL+K, it will become

$ foobarecho -en "\033c""

and, of course, it is not going to work. It is possible to do it?

I suppose it is possible, since that's what CTRL+L does. The only problem with CTRL+L is that it won't clear the entire terminal, including history, just what's on screen.

1
  • 1
    Control+L calls a Readline function clear-screen which takes care restoring the current line after clearing the screen. One possibility is to bind Control-K to a macro consisting of Control-U (kill from the cursor position to the beginning of the line, your echo command, and Control-y (yank the previously killed text back to the current command).
    – chepner
    Nov 21, 2013 at 20:52

2 Answers 2

1

I am not sure how to do that in inputrc, but you can do it with the bind command and its -x option.

bind -x '"\C-K": "echo -en \\033c"'

You can put the above line in your .bashrc and it will offer the same behaviour as the one you describe with CTRL+L.

0
0

do not understand "reset the current terminal". Clean your terminal? If so you can use command clear

2
  • as far as i know, the clear command is to clear the terminal, the reset command is to reset the terminal
    – thom
    Nov 22, 2013 at 1:56
  • If you open a virtual terminal inside X, clear will clear the terminal, but the history will still be there. On the other hand, reset will wipe the history.
    – Marcus
    Dec 4, 2013 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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