1

I want Bash to clear the scrollback history when I press Ctrl+L, especially when I'm running a command with a lot of output; I want to scrollback to the first output line, without overshooting into previous output. And starting a new tab, then switching back to the previous tab and closing it, is not really an option; on my laptop that's Ctrl+Shift+T, Ctrl+Fn+PgDn, Ctrl+D, which is a bit of a handful to type. Following the advice in How to really clear the terminal?, I added the following line to my .bashrc file, after the PS1 definition:

PS1="\u@\h \w\n\$ "
bind -x '"\C-L": tput reset'

However, I then found that after cancelling a long-running Bash command, the terminal stopped echoing standard input when I type, and started showing a modified PS1 prompt. I finally narrowed it down to pressing Ctrl+L, then starting and interrupting a long-running command (for this example find / | head).

hwalters@Wintermute ~
$ 
hwalters@Wintermute ~
$ 
hwalters@Wintermute ~
$ (press Ctrl+L)
hwalters@Wintermute ~
$ find / | head
/
/proc
/proc/fb
/proc/fs
/proc/fs/ext4
/proc/fs/ext4/dm-0
/proc/fs/ext4/dm-0/options
/proc/fs/ext4/dm-0/mb_groups
/proc/fs/ext4/dm-0/es_shrinker_info
/proc/fs/ext4/nvme0n1p2
hwalters@Wintermute ~
$ hwalters@Wintermute ~
$ hwalters@Wintermute ~
$ hwalters@Wintermute ~
$ hello
hwalters@Wintermute ~
$ world
hwalters@Wintermute ~
$ 

I've included the results of pressing Enter a few times, both before and after it goes wrong. Note the two output lines hello and world, which were shown after I entered echo hello and echo world; the echo commands and parameters were not shown as I typed, but were executed.

Note, this does not happen if I enter tput reset instead of pressing Ctrl+L, so it's some combination of that and the key binding. I originally thought it might be a combination of the screen reset and the coloured prompt I generally use, but it happens with the vanilla prompt in this example as well. Any ideas?

If it makes any difference, I'm using Gnome Terminal (3.18.3) in Ubuntu (16.04).

0 Answers0