Name tmux containers by user and session

This commit is contained in:
mpabi
2026-05-11 23:17:56 +02:00
parent 08353cd700
commit c9f4e36709
+20 -3
View File
@@ -3347,11 +3347,18 @@ def tmux_target_exists(session_name: str) -> bool:
return result.returncode == 0
def current_user_slug() -> str:
home_dir = Path(os.environ.get("HOME") or str(Path.home()))
return slug_value(os.environ.get("USER") or home_dir.name or f"uid{os.getuid()}", "user name")
def build_container_command(
config: WorkspaceConfig,
selector: str,
card_path: Path,
instance: str,
session_name: str,
window_name: str,
) -> str:
tool_root = config.tools_root
compose_file = tool_root / "docker-compose.yml"
@@ -3363,10 +3370,16 @@ def build_container_command(
home_dir = Path(os.environ.get("HOME") or str(Path.home()))
card_path_text = str(card_path)
profile = "rv32i"
user_name = current_user_slug()
session_slug = slug_value(session_name, "tmux session name")
instance_name = slug_value(instance, "container instance")
container_name_parts = [user_name, session_slug, profile, instance_name]
container_name = "-".join(container_name_parts)
env_parts = [
f"WORKSPACE_ROOT={shlex.quote(str(config.workspace_root))}",
f"RV_CARDS_ROOT={shlex.quote(str(config.series_root))}",
"RV_PROFILE=rv32i",
f"RV_PROFILE={profile}",
f"RV_REPO={shlex.quote(card_path_text)}",
f"RV_REPO_PATH={shlex.quote(str(card_path))}",
f"RV_REPO_HOST={shlex.quote(str(card_path))}",
@@ -3381,6 +3394,8 @@ def build_container_command(
str(compose_file),
"run",
"--rm",
"--name",
container_name,
"--user",
f"{os.getuid()}:{os.getgid()}",
"--workdir",
@@ -3421,7 +3436,9 @@ def run_tmux_container(config: WorkspaceConfig, args: argparse.Namespace) -> Non
selector = f"{series_name}/{card_name}"
card_path = resolve_card_path(config, series_name, card_name)
session_name = args.session or config.defaults.get("tmux_session", "rv-workspace")
user_name = current_user_slug()
default_session_name = f"rv-{user_name}-{slug_value(selector.replace('/', '-'), 'card selector')}"
session_name = args.session or default_session_name
window_name = args.window or config.defaults.get("tmux_window", "rv")
instance = args.instance or config.defaults.get("instance", "shell")
@@ -3431,7 +3448,7 @@ def run_tmux_container(config: WorkspaceConfig, args: argparse.Namespace) -> Non
"Use another --session name or remove the existing session first."
)
shell_command = build_container_command(config, selector, card_path, instance)
shell_command = build_container_command(config, selector, card_path, instance, session_name, window_name)
tmux_command = [
"tmux",
"new-session",