35

I found this helpful command bind -x '"\C-r"':reset to clear the terminal but I wanted to make a simple bash script:

#!/bin/bash
bind -x '"\C-r"':reset

output:

alfred@alfred-laptop:~/bash$ ./bind 
./bind: line 2: bind: warning: line editing not enabled

Could someone please explain:

  1. How can I fix this?
  2. What does warning: line editing not enabled mean?
squircle
  • 6,717
Alfred
  • 553
  • 1
    I fixed this already using echo -e '\0033\0143' thanks to http://superuser.com/questions/122911/bash-reset-and-clear-commands/123007#123007, but I still would like to know what this error means and how to fix this. Many thanks. – Alfred Feb 01 '11 at 01:55
  • @squircle thanks for good improvements. Might you also know answer to my question :P? – Alfred Feb 01 '11 at 02:10
  • 7
    Just for the record (because this hasn't really been answered): you get "line editing not enabled", because in the bash that is spawned when you invoke your script it simply isn't enabled and you have to do it yourself, .e.g by inserting a set -o emacs or set -o vi into your script (before the bind, of course). – Elmar Zander Nov 27 '15 at 17:01
  • 1
    could try piping it to dev null. bind -x '"\C-r"':reset 2>/dev/null; – john-jones Oct 12 '21 at 11:11
  • Just use Ctrl+L – kingsjester Nov 10 '21 at 08:30
  • @kingsjester that just clears the screen. Reset does that, but in addition, it also resets the terminal to its normal state, in case you or some application messed with its state/capabilities. – ychaouche Dec 07 '23 at 08:29
  • @ychaouche thanks – kingsjester Dec 09 '23 at 16:55

5 Answers5

14

You need to source that script. Do . ./bind or source ./bind to make that key binding active in the current session.

Running it normally, it doesn't have a terminal so it gives you that error message. Also, if it were to work, it would only be active for the duration of the script.

If you want that keybinding to be persistent, add that command to your ~/.bashrc.

  • I know about the persistence. 2. Your example does work, but adds complexity running command(in my opinion). I guess I now know this, but I would like to have a simple bash file which I can run without this source.
  • – Alfred Feb 01 '11 at 02:25
  • 2
    @alfredwesterveld: If you don't want the binding loaded every time you start a shell, but you want to be able to activate it any time without having to use source or dot (.), add a function to your ~/.bashrc: rbind () { bind -x '"\C-r"':reset; } then you can enter rbind by itself as a command and the binding will be activated. – Dennis Williamson Feb 01 '11 at 02:42