Add Herdr agent fork command menu
This commit is contained in:
+37
-2
@@ -22,6 +22,7 @@ from typing import Callable, Iterable, Mapping, Sequence
|
||||
from urllib.parse import quote
|
||||
|
||||
from .aliases import AliasRegistry, AliasRegistryError, default_alias_registry_path
|
||||
from .control import CONTROL_KEY, CONTROL_SHORTCUT, ControlMenu, HerdrControl
|
||||
from .domain import validate_session_name
|
||||
from .remotes import (
|
||||
RegistryError,
|
||||
@@ -581,7 +582,7 @@ class TmuxHub:
|
||||
["set-option", "-g", "mouse", "on"],
|
||||
["set-option", "-g", "focus-events", "on"],
|
||||
["set-option", "-g", "status-left-length", "18"],
|
||||
["set-option", "-g", "status-right-length", "42"],
|
||||
["set-option", "-g", "status-right-length", "64"],
|
||||
[
|
||||
"set-option",
|
||||
"-g",
|
||||
@@ -596,7 +597,7 @@ class TmuxHub:
|
||||
"status-right",
|
||||
"#{?#{<:#{client_width},80},,"
|
||||
"#[dim]#{?pane_dead,连接已断开 · C-a R 重连,"
|
||||
"C-a g choose · q close · r refresh}#[default]}",
|
||||
f"{CONTROL_SHORTCUT} commands · C-a g choose · q close · r refresh}}#[default]}}",
|
||||
],
|
||||
["set-option", "-g", "status-style", "bg=colour235,fg=colour250"],
|
||||
["set-window-option", "-g", "window-status-separator", ""],
|
||||
@@ -638,12 +639,18 @@ class TmuxHub:
|
||||
close = shlex.join(
|
||||
[self.python_bin, self.script_path, "close", "--window", "#{window_id}"]
|
||||
)
|
||||
control = shlex.join([self.python_bin, self.script_path, "control"])
|
||||
confirm_close = shlex.join(["run-shell", "-b", close])
|
||||
# Remove tmux's default/legacy '&' binding when reconfiguring both new
|
||||
# and already-running Hub servers.
|
||||
self.run(["unbind-key", "-T", "prefix", "&"], check=False)
|
||||
self.run(["unbind-key", "-T", "prefix", "Q"], check=False)
|
||||
# Remove the short-lived global binding used by the first control-menu
|
||||
# prototype when reconfiguring an already-running Hub.
|
||||
self.run(["unbind-key", "-T", "root", "C-g"], check=False)
|
||||
binding_commands = [
|
||||
["bind-key", "-T", "prefix", CONTROL_KEY, "display-popup", "-EE",
|
||||
"-w", "80%", "-h", "50%", "-T", "Herdr 命令", control],
|
||||
["bind-key", "-T", "prefix", "C-a", "send-prefix"],
|
||||
["bind-key", "-T", "prefix", "r", "run-shell", "-b", refresh],
|
||||
[
|
||||
@@ -1423,6 +1430,27 @@ def command_choose(arguments: argparse.Namespace) -> int:
|
||||
return 0
|
||||
|
||||
|
||||
def command_control(arguments: argparse.Namespace) -> int:
|
||||
hub = make_hub(arguments, load_aliases=False)
|
||||
windows = hub.managed_windows()
|
||||
if arguments.window:
|
||||
window = next(
|
||||
(item for item in windows if item.window_id == arguments.window),
|
||||
None,
|
||||
)
|
||||
else:
|
||||
active = [item for item in windows if item.active]
|
||||
window = active[0] if len(active) == 1 else None
|
||||
if window is None or window.endpoint is None:
|
||||
raise HubError("无法确定当前 Herdr Hub Tab,请回到 Session 页面后重试")
|
||||
if window.dead:
|
||||
raise HubError("当前 Herdr 连接已断开,请先按 Ctrl+A R 重连")
|
||||
# Endpoint metadata is authoritative; popup environment may belong to another server.
|
||||
binary = resolve_herdr() if window.endpoint.kind == "local" else "herdr"
|
||||
control = HerdrControl(window.endpoint, binary, hub.ssh_bin)
|
||||
return curses.wrapper(ControlMenu(control).run)
|
||||
|
||||
|
||||
def command_remote(arguments: argparse.Namespace) -> int:
|
||||
registry = make_registry()
|
||||
action = arguments.remote_command
|
||||
@@ -1493,6 +1521,10 @@ def command_stop(arguments: argparse.Namespace) -> int:
|
||||
|
||||
def command_doctor(arguments: argparse.Namespace) -> int:
|
||||
failures = 0
|
||||
print(
|
||||
f"control: {CONTROL_SHORTCUT} (Hub prefix); "
|
||||
"Fork requires Herdr 0.9+ on target"
|
||||
)
|
||||
print(f"python: {sys.version.split()[0]} ({sys.executable})")
|
||||
print(f"curses: {getattr(curses, 'version', 'available')}")
|
||||
for binary in ["tmux", "herdr", "ssh"]:
|
||||
@@ -1566,6 +1598,8 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
help="remote attach transport; Windows targets require ssh",
|
||||
)
|
||||
|
||||
control_parser = subparsers.add_parser("control", help="open Herdr commands for the current Hub window")
|
||||
control_parser.add_argument("--window", help="originating tmux window ID")
|
||||
subparsers.add_parser("choose", help="browse and open local or remote sessions")
|
||||
remote_parser = subparsers.add_parser("remote", help="manage remembered remote targets")
|
||||
remote_subparsers = remote_parser.add_subparsers(dest="remote_command")
|
||||
@@ -1609,6 +1643,7 @@ def main(argv: Sequence[str] | None = None) -> int:
|
||||
"refresh": command_refresh,
|
||||
"open": command_open,
|
||||
"choose": command_choose,
|
||||
"control": command_control,
|
||||
"remote": command_remote,
|
||||
"reconnect": command_reconnect,
|
||||
"close": command_close,
|
||||
|
||||
Reference in New Issue
Block a user