I'm using tmux with iTerm2.
Clear screen using Ctrl-L works when i'm in bash, but does not work when i'm tailing server logs. How do i fix this?
You can clear the current buffer using send-keys -R
but keep in mind that the application running inside that buffer will not notice that the buffer contents have been wiped.
Ctrl-L is bound to a readline
command. However, while you are running the command that tails your log, bash
is not receiving keyboard input. You could suspend the tail with Ctrl-Z, clear the screen with Ctrl-L, and resume the tail with fg
.
This is independent of tmux
; I don't think tmux
has anything like a clear-pane
command, instead relying on the shell to handle that for you.
In OSX (Terminal and I believe iTerm2), CMD+K clears and removes scrollback but I'm not sure this works when tailing or in tmux.
A couple of links may have your answer:
Also, @chepner suggested suspending the command and this gave me the idea to add it as a key binding (note: I've tested this on Linux but I don't have OSX. The first link seems to indicate clear-history
may work):
bind-key -n C-l send-keys C-z \; send-keys " reset && fg > /dev/null" \; send-keys "Enter"
Add this to your ~/.tmux.conf
then you can do CTRL+l
and that will send the required keys and commands to the terminal to automate it.
reset && fg
is prefixed with a space to exclude it from history.
The > /dev/null
stops the original tail command being displayed but this might be useful so could be removed if you want to see it after clearing.