agent-command-tab 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agent_command_tab/__init__.py +4 -0
- agent_command_tab/agent_adapters/__init__.py +48 -0
- agent_command_tab/agent_adapters/base.py +162 -0
- agent_command_tab/agent_adapters/claude_code.py +120 -0
- agent_command_tab/agent_adapters/codex.py +102 -0
- agent_command_tab/agent_adapters/generic.py +22 -0
- agent_command_tab/agent_process_tree.py +557 -0
- agent_command_tab/agent_session_pausing.py +254 -0
- agent_command_tab/app_controller.py +947 -0
- agent_command_tab/claude_code_transcript_records.py +75 -0
- agent_command_tab/command_line.py +187 -0
- agent_command_tab/context_window_usage.py +230 -0
- agent_command_tab/dashboard_core_api.py +57 -0
- agent_command_tab/docked_window_frames_store.py +60 -0
- agent_command_tab/global_shortcut_key_filter.py +167 -0
- agent_command_tab/hook_event_forwarder.py +116 -0
- agent_command_tab/hook_event_tracking.py +129 -0
- agent_command_tab/hook_states_store.py +60 -0
- agent_command_tab/hooks_installer.py +300 -0
- agent_command_tab/installed_copy_paths.py +41 -0
- agent_command_tab/iterm2_actions.py +325 -0
- agent_command_tab/iterm2_connection_thread.py +2299 -0
- agent_command_tab/iterm2_snapshot_builder.py +403 -0
- agent_command_tab/list_sorting.py +117 -0
- agent_command_tab/messages_between_agent_sessions.py +78 -0
- agent_command_tab/monitor_assignment.py +109 -0
- agent_command_tab/pause_records_store.py +61 -0
- agent_command_tab/screen_readings.py +108 -0
- agent_command_tab/session_preview_computation.py +228 -0
- agent_command_tab/session_status_computation.py +235 -0
- agent_command_tab/settings_store.py +292 -0
- agent_command_tab/snapshot_data_classes.py +145 -0
- agent_command_tab/start_with_iterm2.py +138 -0
- agent_command_tab/tab_order_computation.py +26 -0
- agent_command_tab/user_interface/__init__.py +1 -0
- agent_command_tab/user_interface/agent_session_outline_view.py +2120 -0
- agent_command_tab/user_interface/agent_tool_icons.py +124 -0
- agent_command_tab/user_interface/app_icon.py +75 -0
- agent_command_tab/user_interface/control_helpers.py +38 -0
- agent_command_tab/user_interface/list_window.py +116 -0
- agent_command_tab/user_interface/menu_bar_status_item.py +193 -0
- agent_command_tab/user_interface/named_colors.py +58 -0
- agent_command_tab/user_interface/pointing_hand_button.py +42 -0
- agent_command_tab/user_interface/popover_container.py +461 -0
- agent_command_tab/user_interface/row_text_rendering.py +342 -0
- agent_command_tab/user_interface/screen_layout.py +91 -0
- agent_command_tab/user_interface/settings_window.py +530 -0
- agent_command_tab/user_interface/sidebar_panel.py +486 -0
- agent_command_tab/user_interface/sidebar_placement.py +105 -0
- agent_command_tab/user_interface/talk_to_each_other_alert.py +130 -0
- agent_command_tab/window_list_ordering.py +44 -0
- agent_command_tab-0.1.0.dist-info/METADATA +85 -0
- agent_command_tab-0.1.0.dist-info/RECORD +57 -0
- agent_command_tab-0.1.0.dist-info/WHEEL +5 -0
- agent_command_tab-0.1.0.dist-info/entry_points.txt +2 -0
- agent_command_tab-0.1.0.dist-info/licenses/LICENSE +21 -0
- agent_command_tab-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"""The snapshot that the core publishes to every view.
|
|
2
|
+
|
|
3
|
+
Plain, immutable records that convert to JSON, so that a later web page, phone app or second
|
|
4
|
+
computer can receive exactly what the menu bar list receives. They are named tuples (not data
|
|
5
|
+
classes, which would need type annotations), so equal contents compare equal, which the views
|
|
6
|
+
use to redraw only the rows that changed. Frames are (x, y, width, height) tuples in points,
|
|
7
|
+
with the origin at the bottom-left of the main monitor.
|
|
8
|
+
|
|
9
|
+
The fields once kept for importance levels, hover panels, automatic introductions, the startup
|
|
10
|
+
window order and Codex usage bars were removed when those features were dropped (user decision,
|
|
11
|
+
2026-10-27).
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import collections
|
|
15
|
+
|
|
16
|
+
# Each optional field beside its default, so a field added or moved can't take another's default.
|
|
17
|
+
AGENT_SESSION_ENTRY_DEFAULTS_BY_OPTIONAL_FIELD = {
|
|
18
|
+
"status_reason": "", "status_since": 0.0, "preview_line": "", "context_fill_percent": None,
|
|
19
|
+
"background_task_count": 0, "ended_abnormally_at": None, "is_in_front": False, "last_time_tab_was_seen": None,
|
|
20
|
+
"running_tool_name": "", "running_tool_started_at": None, "context_tokens": None, "started_at": None,
|
|
21
|
+
"memory_bytes": None, "cpu_percent": None, "slash_commands": (), "is_paused_with_the_processes_below_it": False,
|
|
22
|
+
"child_processes": (),
|
|
23
|
+
}
|
|
24
|
+
AgentSessionEntry = collections.namedtuple(
|
|
25
|
+
"AgentSessionEntry",
|
|
26
|
+
["tab_id", "session_id", "tab_title", "tab_title_set_by_user", "agent_session_name", "agent_tool_name",
|
|
27
|
+
"working_folder", "status"] + list(AGENT_SESSION_ENTRY_DEFAULTS_BY_OPTIONAL_FIELD),
|
|
28
|
+
defaults=list(AGENT_SESSION_ENTRY_DEFAULTS_BY_OPTIONAL_FIELD.values()),
|
|
29
|
+
)
|
|
30
|
+
AgentSessionEntry.__doc__ = ("One iTerm2 tab whose first pane runs an agent session. last_time_tab_was_seen is when "
|
|
31
|
+
"the tab was last selected in the key iTerm2 window while iTerm2 was active, or None. "
|
|
32
|
+
"running_tool_name is the tool a working agent waits on, and running_tool_started_at "
|
|
33
|
+
"when it started (iterm2_snapshot_builder.choose_tool_the_agent_is_waiting_on): a "
|
|
34
|
+
"command it started in this turn (for example \"python3\"), or another tool open for "
|
|
35
|
+
"5 seconds or more (for example \"Agent\"), or \"\" while it thinks (\"running_command_"
|
|
36
|
+
"name\" until 2026-10-28, when other tools began to count). context_tokens is how many "
|
|
37
|
+
"tokens its context holds, from its conversation file, or None if unknown, and "
|
|
38
|
+
"context_fill_percent that as a whole percent of its context window, or None. "
|
|
39
|
+
"started_at is when the agent's process started (the Created Time column), or None. "
|
|
40
|
+
"preview_line is the gray line under the tab row: what the agent asks or runs, what "
|
|
41
|
+
"it said since the last prompt, or that prompt (session_preview_computation). "
|
|
42
|
+
"memory_bytes and cpu_percent are what the agent process and all the processes below it "
|
|
43
|
+
"use (physical memory to the megabyte; percent of one CPU core, a whole number), or "
|
|
44
|
+
"None until they are read. slash_commands are the commands the tab's menu can type "
|
|
45
|
+
"into its agent tool (its adapter's), in menu order. is_paused_with_the_processes_below_it "
|
|
46
|
+
"is True for a paused row whose pause also stopped the processes below the agent (Pause "
|
|
47
|
+
"from the list), False for an agent suspended with Ctrl+Z by hand. A row whose agent "
|
|
48
|
+
"ended without a normal session end (a crash, or killed) has the status "
|
|
49
|
+
"\"exited\" and ended_abnormally_at, when that was noticed. background_task_count is "
|
|
50
|
+
"how many background shells and background agents it runs, and "
|
|
51
|
+
"child_processes the ChildProcessEntry of each process it started, oldest first.")
|
|
52
|
+
|
|
53
|
+
ChildProcessEntry = collections.namedtuple(
|
|
54
|
+
"ChildProcessEntry", ["process_id", "command_text", "started_at", "is_background_shell", "memory_bytes", "cpu_percent"])
|
|
55
|
+
ChildProcessEntry.__doc__ = ("One process an agent started, a sub row of its open tab row (user request, 2026-10-27): "
|
|
56
|
+
"the command it runs (agent_process_tree.list_child_processes_of_the_agent), when that "
|
|
57
|
+
"command started, whether it is a command left running in the background, and what it and the "
|
|
58
|
+
"processes below it use (None while memory and CPU use aren't read).")
|
|
59
|
+
|
|
60
|
+
WindowEntry = collections.namedtuple(
|
|
61
|
+
"WindowEntry",
|
|
62
|
+
["window_id", "title", "window_title_set_by_user", "frame", "total_tab_count", "agent_sessions", "selected_tab_id"],
|
|
63
|
+
defaults=[None],
|
|
64
|
+
)
|
|
65
|
+
WindowEntry.__doc__ = ("One iTerm2 window with at least one agent session tab. total_tab_count includes the tabs "
|
|
66
|
+
"that are hidden because they run no agent. selected_tab_id is the window's own selected "
|
|
67
|
+
"tab, which may run no agent (unlike is_in_front, which marks only the key window's tab).")
|
|
68
|
+
|
|
69
|
+
MonitorEntry = collections.namedtuple("MonitorEntry", ["monitor_id", "name", "frame", "visible_frame", "windows"])
|
|
70
|
+
MonitorEntry.__doc__ = "One monitor and the windows assigned to it, in the core's window list order."
|
|
71
|
+
|
|
72
|
+
ComputerSnapshot = collections.namedtuple(
|
|
73
|
+
"ComputerSnapshot", ["computer_id", "computer_name", "taken_at", "monitors", "hooks_status_per_agent_tool"],
|
|
74
|
+
defaults=[()],
|
|
75
|
+
)
|
|
76
|
+
ComputerSnapshot.__doc__ = ("Everything one computer's core knows, at one moment. hooks_status_per_agent_tool holds "
|
|
77
|
+
"(agent tool name, hooks_installer.check_hooks's status) pairs, one for each tool the "
|
|
78
|
+
"app has hooks for (user request, 2026-10-27).")
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def convert_snapshot_to_json_ready_dict(snapshot):
|
|
82
|
+
"""Returns the snapshot as nested dicts and lists that json.dumps accepts.
|
|
83
|
+
|
|
84
|
+
Args:
|
|
85
|
+
snapshot: A ComputerSnapshot, or any of the records above.
|
|
86
|
+
|
|
87
|
+
Returns:
|
|
88
|
+
A dict (for a record), a list (for a tuple of records), or the value itself.
|
|
89
|
+
"""
|
|
90
|
+
if hasattr(snapshot, "_asdict"):
|
|
91
|
+
return {field_name: convert_snapshot_to_json_ready_dict(value) for field_name, value in snapshot._asdict().items()}
|
|
92
|
+
if isinstance(snapshot, (tuple, list)):
|
|
93
|
+
return [convert_snapshot_to_json_ready_dict(value) for value in snapshot]
|
|
94
|
+
return snapshot
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def replace_title_in_snapshot(snapshot, kind, item_id, new_title):
|
|
98
|
+
"""Returns the snapshot with one window's title (kind "window") or one tab's title (kind
|
|
99
|
+
"tab") replaced, for a rename the list shows before a snapshot from the core confirms it."""
|
|
100
|
+
|
|
101
|
+
def replace_title_in_window(window_entry):
|
|
102
|
+
if kind == "window":
|
|
103
|
+
return window_entry._replace(title=new_title) if window_entry.window_id == item_id else window_entry
|
|
104
|
+
return window_entry._replace(agent_sessions=tuple(
|
|
105
|
+
entry._replace(tab_title=new_title) if entry.tab_id == item_id else entry for entry in window_entry.agent_sessions))
|
|
106
|
+
return snapshot._replace(monitors=tuple(
|
|
107
|
+
monitor_entry._replace(windows=tuple(replace_title_in_window(window_entry) for window_entry in monitor_entry.windows))
|
|
108
|
+
for monitor_entry in snapshot.monitors))
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def iterate_agent_session_entries(snapshot):
|
|
112
|
+
"""Yields (monitor_entry, window_entry, agent_session_entry) for every agent session.
|
|
113
|
+
|
|
114
|
+
Args:
|
|
115
|
+
snapshot: A ComputerSnapshot.
|
|
116
|
+
"""
|
|
117
|
+
for monitor_entry in snapshot.monitors:
|
|
118
|
+
for window_entry in monitor_entry.windows:
|
|
119
|
+
for agent_session_entry in window_entry.agent_sessions:
|
|
120
|
+
yield monitor_entry, window_entry, agent_session_entry
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
SECONDS_A_TAB_COUNTS_AS_RECENTLY_USED = 24 * 60 * 60
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def choose_folder_for_new_agent_window(snapshot, now, home_folder):
|
|
127
|
+
"""Returns the folder a new window's agent session starts in (user request, milestone 2): the
|
|
128
|
+
folder of the tab in front, else of the tab seen most recently within the last 24 hours,
|
|
129
|
+
else the home folder.
|
|
130
|
+
|
|
131
|
+
Args:
|
|
132
|
+
snapshot: The latest ComputerSnapshot, or None before the first one.
|
|
133
|
+
now: The current time.
|
|
134
|
+
home_folder: The user's home folder.
|
|
135
|
+
"""
|
|
136
|
+
agent_session_entries = [entry for _, _, entry in iterate_agent_session_entries(snapshot) if entry.working_folder] \
|
|
137
|
+
if snapshot else []
|
|
138
|
+
front_entry = next((entry for entry in agent_session_entries if entry.is_in_front), None)
|
|
139
|
+
if front_entry is not None:
|
|
140
|
+
return front_entry.working_folder
|
|
141
|
+
recently_seen_entries = [entry for entry in agent_session_entries if entry.last_time_tab_was_seen is not None
|
|
142
|
+
and now - entry.last_time_tab_was_seen <= SECONDS_A_TAB_COUNTS_AS_RECENTLY_USED]
|
|
143
|
+
if recently_seen_entries:
|
|
144
|
+
return max(recently_seen_entries, key=lambda entry: entry.last_time_tab_was_seen).working_folder
|
|
145
|
+
return home_folder
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"""Starting the app whenever iTerm2 starts (user request, 2026-10-28): an AppleScript in iTerm2's
|
|
2
|
+
AutoLaunch folder, which iTerm2 runs each time it starts, that starts this copy of the app however it
|
|
3
|
+
was installed (pip, pipx or Homebrew).
|
|
4
|
+
|
|
5
|
+
A program started this way runs with iTerm2's macOS permissions, as one started from an iTerm2 tab
|
|
6
|
+
does, so the keyboard shortcut keeps the Accessibility permission given to iTerm2. A launch agent that
|
|
7
|
+
started the app at login (tried first, 2026-10-28) ran it as the Python interpreter itself, which lacks
|
|
8
|
+
that permission, and macOS listed it in Login Items as "python". iTerm2 runs a .py AutoLaunch script
|
|
9
|
+
only with its own Python runtime, a separate download, so this one is an AppleScript, which iTerm2 runs
|
|
10
|
+
as it is (checked with iTerm2 3.7.6, and in its source: iTermScriptsMenuController.m).
|
|
11
|
+
|
|
12
|
+
The app adds the script when it starts while the settings' "Start with iTerm2" is on (the default), and
|
|
13
|
+
takes it out when that is turned off. A script already there is kept while the program it starts
|
|
14
|
+
exists, so the copy that added it keeps starting; one whose program is gone (that copy was uninstalled)
|
|
15
|
+
is written again for this copy. A copy started while another runs exits at once (command_line's running
|
|
16
|
+
lock), so reopening iTerm2 while the app still runs doesn't start a second copy.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
import os
|
|
20
|
+
import plistlib
|
|
21
|
+
import shlex
|
|
22
|
+
import subprocess
|
|
23
|
+
|
|
24
|
+
from agent_command_tab.installed_copy_paths import find_python_of_this_copy, replace_homebrew_version_folder_with_its_stable_link
|
|
25
|
+
|
|
26
|
+
AUTOLAUNCH_SCRIPT_FILE_NAME = "AgentCommandTab.scpt"
|
|
27
|
+
ITERM2_PREFERENCES_FILE_PATH = os.path.expanduser("~/Library/Preferences/com.googlecode.iterm2.plist")
|
|
28
|
+
# iTerm2's scripts folder, unless its settings name another (find_iterm2_autolaunch_folder). iTerm2
|
|
29
|
+
# reaches it through ~/.config/iterm2/AppSupport, a link to ~/Library/Application Support/iTerm2.
|
|
30
|
+
ITERM2_SCRIPTS_FOLDER = os.path.expanduser("~/Library/Application Support/iTerm2/Scripts")
|
|
31
|
+
LOG_FILE_PATH = os.path.expanduser("~/Library/Logs/agent-command-tab.log")
|
|
32
|
+
# The AppleScript's line that names the program it starts, read back by read_program_of_autolaunch_script.
|
|
33
|
+
PROGRAM_COMMENT_PREFIX = "-- program: "
|
|
34
|
+
SECONDS_TO_WAIT_FOR_THE_APPLESCRIPT_COMPILER = 30
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def find_iterm2_autolaunch_folder(preferences_file_path=ITERM2_PREFERENCES_FILE_PATH):
|
|
38
|
+
"""Returns the AutoLaunch folder iTerm2 runs scripts from: in the scripts folder its settings name
|
|
39
|
+
(General > Magic > "Use custom scripts folder"; one that has a space in its path or isn't a folder
|
|
40
|
+
is ignored, as iTerm2 does), else in ITERM2_SCRIPTS_FOLDER."""
|
|
41
|
+
try:
|
|
42
|
+
with open(preferences_file_path, "rb") as preferences_file:
|
|
43
|
+
preferences = plistlib.load(preferences_file)
|
|
44
|
+
except (OSError, ValueError): # plistlib.InvalidFileException is a ValueError
|
|
45
|
+
preferences = {}
|
|
46
|
+
custom_scripts_folder = preferences.get("CustomScriptsFolder") if isinstance(preferences, dict) else None
|
|
47
|
+
if preferences.get("UseCustomScriptsFolder") is True and isinstance(custom_scripts_folder, str):
|
|
48
|
+
custom_scripts_folder = os.path.expanduser(custom_scripts_folder)
|
|
49
|
+
if " " not in custom_scripts_folder and os.path.isdir(custom_scripts_folder):
|
|
50
|
+
return os.path.join(custom_scripts_folder, "AutoLaunch")
|
|
51
|
+
return os.path.join(ITERM2_SCRIPTS_FOLDER, "AutoLaunch")
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def build_command_that_starts_this_copy_of_the_app(python_path=None):
|
|
55
|
+
"""Returns the program and arguments that start this copy of the app, restarted when iTerm2's
|
|
56
|
+
connection drops (`agent-command-tab run`): the Python running the app (python_path, or
|
|
57
|
+
find_python_of_this_copy's), by a path that survives upgrades, running the command line module."""
|
|
58
|
+
return [replace_homebrew_version_folder_with_its_stable_link(python_path) if python_path else find_python_of_this_copy(),
|
|
59
|
+
"-m", "agent_command_tab.command_line", "run"]
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def escape_for_applescript_string(text):
|
|
63
|
+
"""Returns text to put between an AppleScript string's double quotes."""
|
|
64
|
+
return text.replace("\\", "\\\\").replace('"', '\\"')
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def build_autolaunch_script_source(program_arguments, log_file_path=LOG_FILE_PATH):
|
|
68
|
+
"""Returns the AppleScript that starts program_arguments in the background, with its output
|
|
69
|
+
appended to log_file_path, and returns at once (do shell script waits for a command unless its
|
|
70
|
+
output is redirected and it ends in &)."""
|
|
71
|
+
shell_command = (" ".join(shlex.quote(argument) for argument in program_arguments)
|
|
72
|
+
+ f" >> {shlex.quote(log_file_path)} 2>&1 &")
|
|
73
|
+
return ("-- Added by AgentCommandTab, which iTerm2 starts with this script whenever iTerm2 starts.\n"
|
|
74
|
+
"-- AgentCommandTab's Settings > Start with iTerm2 removes it.\n"
|
|
75
|
+
f"{PROGRAM_COMMENT_PREFIX}{program_arguments[0]}\n"
|
|
76
|
+
f'do shell script "{escape_for_applescript_string(shell_command)}"\n')
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def read_program_of_autolaunch_script(autolaunch_script_path):
|
|
80
|
+
"""Returns the program the AutoLaunch script starts (its PROGRAM_COMMENT_PREFIX line, read with
|
|
81
|
+
osadecompile), or None when there is no such script or it names none."""
|
|
82
|
+
if not os.path.exists(autolaunch_script_path):
|
|
83
|
+
return None
|
|
84
|
+
try:
|
|
85
|
+
source = subprocess.run(["/usr/bin/osadecompile", autolaunch_script_path], capture_output=True, text=True,
|
|
86
|
+
check=True, timeout=SECONDS_TO_WAIT_FOR_THE_APPLESCRIPT_COMPILER).stdout
|
|
87
|
+
except (OSError, subprocess.SubprocessError):
|
|
88
|
+
return None
|
|
89
|
+
return next((line[len(PROGRAM_COMMENT_PREFIX):] for line in source.splitlines() if line.startswith(PROGRAM_COMMENT_PREFIX)),
|
|
90
|
+
None)
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
def write_autolaunch_script(source, autolaunch_script_path):
|
|
94
|
+
"""Compiles the AppleScript source with osacompile into a hidden file next to
|
|
95
|
+
autolaunch_script_path (iTerm2 skips names that start with a dot), which then replaces it.
|
|
96
|
+
|
|
97
|
+
Raises:
|
|
98
|
+
OSError: The folder can't be made, or osacompile fails (its message is in the error).
|
|
99
|
+
"""
|
|
100
|
+
folder = os.path.dirname(autolaunch_script_path)
|
|
101
|
+
os.makedirs(folder, exist_ok=True)
|
|
102
|
+
temporary_path = os.path.join(folder, f".{os.getpid()}-{os.path.basename(autolaunch_script_path)}")
|
|
103
|
+
try:
|
|
104
|
+
completed_process = subprocess.run(["/usr/bin/osacompile", "-o", temporary_path], input=source, capture_output=True,
|
|
105
|
+
text=True, timeout=SECONDS_TO_WAIT_FOR_THE_APPLESCRIPT_COMPILER)
|
|
106
|
+
except subprocess.TimeoutExpired as error:
|
|
107
|
+
raise OSError(f"osacompile didn't finish: {error}") from error
|
|
108
|
+
if completed_process.returncode != 0:
|
|
109
|
+
if os.path.exists(temporary_path):
|
|
110
|
+
os.remove(temporary_path)
|
|
111
|
+
raise OSError(f"osacompile failed: {completed_process.stderr.strip()}")
|
|
112
|
+
os.replace(temporary_path, autolaunch_script_path)
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def update_autolaunch_script_to_match_setting(app_starts_with_iterm2, program_arguments, autolaunch_script_path,
|
|
116
|
+
log_file_path=LOG_FILE_PATH):
|
|
117
|
+
"""Adds, keeps or removes the AutoLaunch script so that it matches the "Start with iTerm2" setting.
|
|
118
|
+
|
|
119
|
+
Args:
|
|
120
|
+
app_starts_with_iterm2: The setting.
|
|
121
|
+
program_arguments: build_command_that_starts_this_copy_of_the_app's command, written into a
|
|
122
|
+
new script.
|
|
123
|
+
autolaunch_script_path: Where iTerm2 finds it (find_iterm2_autolaunch_folder, AUTOLAUNCH_SCRIPT_FILE_NAME).
|
|
124
|
+
log_file_path: Where the app started by iTerm2 writes its output.
|
|
125
|
+
|
|
126
|
+
Returns:
|
|
127
|
+
"added", "kept", "removed" or "nothing" (off, and there was no script).
|
|
128
|
+
"""
|
|
129
|
+
if not app_starts_with_iterm2:
|
|
130
|
+
if not os.path.lexists(autolaunch_script_path):
|
|
131
|
+
return "nothing"
|
|
132
|
+
os.remove(autolaunch_script_path)
|
|
133
|
+
return "removed"
|
|
134
|
+
program = read_program_of_autolaunch_script(autolaunch_script_path)
|
|
135
|
+
if program is not None and os.path.exists(program):
|
|
136
|
+
return "kept"
|
|
137
|
+
write_autolaunch_script(build_autolaunch_script_source(program_arguments, log_file_path), autolaunch_script_path)
|
|
138
|
+
return "added"
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""The full iTerm2 tab order after a tab row is dragged.
|
|
2
|
+
|
|
3
|
+
The list hides tabs without an agent, but iTerm2 needs every tab of a window in its new order.
|
|
4
|
+
Hidden tabs keep their place relative to their neighbors.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def compute_full_tab_order_after_move(full_tab_ids, moved_tab_id, drop_before_visible_tab_id):
|
|
9
|
+
"""Returns every tab ID of the target window in its new order.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
full_tab_ids: All tab IDs of the target window in iTerm2's order, hidden tabs included.
|
|
13
|
+
For a move from another window, moved_tab_id is not among them yet.
|
|
14
|
+
moved_tab_id: The dragged tab.
|
|
15
|
+
drop_before_visible_tab_id: The listed tab it was dropped before, or None for after the
|
|
16
|
+
window's last tab.
|
|
17
|
+
|
|
18
|
+
Returns:
|
|
19
|
+
A list of tab IDs that contains moved_tab_id exactly once.
|
|
20
|
+
"""
|
|
21
|
+
remaining_tab_ids = [tab_id for tab_id in full_tab_ids if tab_id != moved_tab_id]
|
|
22
|
+
if drop_before_visible_tab_id in remaining_tab_ids:
|
|
23
|
+
insert_position = remaining_tab_ids.index(drop_before_visible_tab_id)
|
|
24
|
+
else:
|
|
25
|
+
insert_position = len(remaining_tab_ids)
|
|
26
|
+
return remaining_tab_ids[:insert_position] + [moved_tab_id] + remaining_tab_ids[insert_position:]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""The AppKit views: menu bar item, dropdown list, sidebar. Runs on the main thread only."""
|