OSX Shell Clearing Tip2015-07-26T11:07:47.401194-05:00 2015-07-26T11:07:47.401194-05:00 2015-08-23T10:10:32.970485-05:00
First off you’re serious about your shell and using Mac OSX for development you should really be using iTerm2 instead of the built in default Terminal app.
That being said, here is a handy keyboard shortcut that works with both iTerm2 and Terminal.app. I often find myself running something like:
$ find ./ | grep tests .//blogs/tests .//blogs/tests/__init__.py .//blogs/tests/__pycache__ .//blogs/tests/__pycache__/__init__.cpython-33.pyc .//blogs/tests/__pycache__/test_models.cpython-33.pyc .//blogs/tests/__pycache__/test_parser.cpython-33.pyc .//blogs/tests/__pycache__/test_templatetags.cpython-33.pyc .//blogs/tests/__pycache__/test_views.cpython-33.pyc .//blogs/tests/__pycache__/utils.cpython-33.pyc .//blogs/tests/psf_feed_example.xml .//blogs/tests/test_models.py .//blogs/tests/test_parser.py .//blogs/tests/test_templatetags.py .//blogs/tests/test_views.py .//blogs/tests/utils.py .//boxes/__pycache__/tests.cpython-33.pyc .//boxes/tests.py .//chef/cookbooks/postgresql/files/default/tests .//chef/cookbooks/postgresql/files/default/tests/minitest .//chef/cookbooks/postgresql/files/default/tests/minitest/apt_pgdg_postgresql_test.rb .//chef/cookbooks/postgresql/files/default/tests/minitest/default_test.rb .//chef/cookbooks/postgresql/files/default/tests/minitest/ruby_test.rb .//chef/cookbooks/postgresql/files/default/tests/minitest/server_test.rb .//chef/cookbooks/postgresql/files/default/tests/minitest/support .//chef/cookbooks/postgresql/files/default/tests/minitest/support/helpers.rb ....
Which returns a ton more results than I intended. Which leads to piping the results to another grep or two to quickly find what I’m looking for in a file tree. But if you immediately run another shell command both of the results are in your scroll buffer which isn’t exactly optimal all of the time.
Hitting Cmd+k will clear the shell buffer (aka scroll buffer) without clearing out your history or the current text at your shell prompt. “k for clear” is how I remember it. So you can for example hit up arrow and add
| grep -v '.pyc'
to the previous shell command and THEN hit Cmd+k and it will clear your scroll buffer without clearing the edits to your command.
This way your scroll buffer only contains the output of the immediately preceding command and nothing else. Hope this helps!