Name tmux containers by user and session
This commit is contained in:
@@ -3347,11 +3347,18 @@ def tmux_target_exists(session_name: str) -> bool:
|
|||||||
return result.returncode == 0
|
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(
|
def build_container_command(
|
||||||
config: WorkspaceConfig,
|
config: WorkspaceConfig,
|
||||||
selector: str,
|
selector: str,
|
||||||
card_path: Path,
|
card_path: Path,
|
||||||
instance: str,
|
instance: str,
|
||||||
|
session_name: str,
|
||||||
|
window_name: str,
|
||||||
) -> str:
|
) -> str:
|
||||||
tool_root = config.tools_root
|
tool_root = config.tools_root
|
||||||
compose_file = tool_root / "docker-compose.yml"
|
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()))
|
home_dir = Path(os.environ.get("HOME") or str(Path.home()))
|
||||||
card_path_text = str(card_path)
|
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 = [
|
env_parts = [
|
||||||
f"WORKSPACE_ROOT={shlex.quote(str(config.workspace_root))}",
|
f"WORKSPACE_ROOT={shlex.quote(str(config.workspace_root))}",
|
||||||
f"RV_CARDS_ROOT={shlex.quote(str(config.series_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={shlex.quote(card_path_text)}",
|
||||||
f"RV_REPO_PATH={shlex.quote(str(card_path))}",
|
f"RV_REPO_PATH={shlex.quote(str(card_path))}",
|
||||||
f"RV_REPO_HOST={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),
|
str(compose_file),
|
||||||
"run",
|
"run",
|
||||||
"--rm",
|
"--rm",
|
||||||
|
"--name",
|
||||||
|
container_name,
|
||||||
"--user",
|
"--user",
|
||||||
f"{os.getuid()}:{os.getgid()}",
|
f"{os.getuid()}:{os.getgid()}",
|
||||||
"--workdir",
|
"--workdir",
|
||||||
@@ -3421,7 +3436,9 @@ def run_tmux_container(config: WorkspaceConfig, args: argparse.Namespace) -> Non
|
|||||||
selector = f"{series_name}/{card_name}"
|
selector = f"{series_name}/{card_name}"
|
||||||
card_path = resolve_card_path(config, 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")
|
window_name = args.window or config.defaults.get("tmux_window", "rv")
|
||||||
instance = args.instance or config.defaults.get("instance", "shell")
|
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."
|
"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_command = [
|
||||||
"tmux",
|
"tmux",
|
||||||
"new-session",
|
"new-session",
|
||||||
|
|||||||
Reference in New Issue
Block a user