iTerm2 is my default terminal and have been using it for close to 8 years now. It is highly customizable and has API support for hackability.
I was using it today to run a webpack watch command on my 2nd monitor. For every change, webpack recompiles the modified files and adds it to the output. Since every output looks the same, it wasn’t really clear if my change has been re-compiled or not.
I wrote a small script that will clear the scrollback of the current tab session every 10 seconds. This will ensure me that the last re-compilation step is the only one shown on the view.
Here are the steps:
- Open iTerm2
- Scripts -> Manage scripts -> New Python script
- Basic -> Simple
- Choose the default location and type
clear_scrollback_on_schedule
for the name - Paste the following code in the text editor opened and save
- Open the tab where you want to execute the script and press
Shift + Cmd + O
(shortcut forOpen Quickly
) and typescroll
and you should see the new script. PressEnter
to launch the script - Now the current tab’s scrollback should be cleared every 10 seconds!
Here is the full script:
#!/usr/bin/env python3.7 import iterm2 import time async def main(connection): app = await iterm2.async_get_app(connection) window = app.current_terminal_window if window is not None: tab = window.current_tab if tab is not None: while True: for session in tab.sessions: code = b'\x1b' + b']1337;ClearScrollback' + b'\x07' await session.async_inject(code) time.sleep(10) else: print("No current tab") else: print("No current window") iterm2.run_until_complete(main)
Reference – https://iterm2.com/python-api/examples/cls.html
Open Quickly window:
MOST COMMENTED
Flutter
Flutter Setup
React Native
Learn React Native with a Board Game (Part 1 of 4)
jQuery / Web Development
jQuery DataTable: Sorting dynamic data
Uncategorized
Hibernate – Associations are not loaded
Database / Java / MySQL / Spring Boot
Hibernate Error – Encountered problem trying to hydrate identifier for entity
Spring Boot / Uncategorized
Working with Hibernate in a multi-threaded application
Web Development
Designing REST APIs