How do i clear tmux screen while tailing logs?

最后都变了- 提交于 2019-11-30 01:50:15

问题


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?


回答1:


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.

Reference




回答2:


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.




回答3:


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:

  • https://coderwall.com/p/rkstvg
  • https://apple.stackexchange.com/questions/31872/how-do-i-reset-the-scrollback-in-the-terminal-via-a-shell-command

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.



来源:https://stackoverflow.com/questions/14731760/how-do-i-clear-tmux-screen-while-tailing-logs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!