iTerm2
1.24
iTerm2 是 macOS 环境常用的终端模拟器(terminal emulator),包含很多方便的特性。
color schemes
https://iterm2colorschemes.com/
-
Download
*.itermcolors
-
Setting > Profile > Color Presets > import
Python API
支持通过 Python 来控制和扩展终端。
Example: Open new tab
python3 new-tab.py
new-tab.py
#!/usr/bin/env python3.7
import iterm2
import sys
cwd_path = sys.argv[1] if len(sys.argv) > 1 else None
async def main(connection):
# Your code goes here. Here's a bit of example code that adds a tab to the current window:
app = await iterm2.async_get_app(connection)
window = app.current_terminal_window
await newTabOrWindow(window, connection)
async def newTabOrWindow(window, connection):
change = iterm2.LocalWriteOnlyProfile()
if window is not None:
change.set_advanced_working_directory_tab_directory(cwd_path or '~')
await window.async_create_tab(profile_customizations=change)
session = window.current_tab.current_session
cwd = 'cd ' + cwd_path + ''
await session.async_send_text('alias dp="' + cwd + '"\n')
else:
change.set_advanced_working_directory_window_directory(cwd_path or '~')
await iterm2.Window.async_create(connection, profile_customizations=change)
# You can view this message in the script console.
print("No current window")
# async def changeTab(window):
# color = iterm2.Color(255, 128, 128)
# change.set_tab_color(color)
# change.set_use_tab_color(True)
# change.set_allow_title_setting(False)
# change.set_name('Hello')
# session = window.current_tab.current_session
# await session.async_set_profile_properties(change)
iterm2.run_until_complete(main)
📖