consistent tmux-session names
This commit is contained in:
parent
ae5b47764b
commit
b67d96f6b8
1 changed files with 32 additions and 3 deletions
|
|
@ -462,6 +462,7 @@ def list_repos(
|
||||||
"""
|
"""
|
||||||
_settings, _repos_dir, workspaces_dir = get_ctx_paths(ctx)
|
_settings, _repos_dir, workspaces_dir = get_ctx_paths(ctx)
|
||||||
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
||||||
|
workspace = ws_dir.name
|
||||||
|
|
||||||
if not ws_dir.exists():
|
if not ws_dir.exists():
|
||||||
console.print(
|
console.print(
|
||||||
|
|
@ -569,6 +570,8 @@ def add_repo(
|
||||||
"""
|
"""
|
||||||
_settings, repos_dir, workspaces_dir = get_ctx_paths(ctx)
|
_settings, repos_dir, workspaces_dir = get_ctx_paths(ctx)
|
||||||
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
||||||
|
workspace = ws_dir.name
|
||||||
|
|
||||||
if not ws_dir.exists():
|
if not ws_dir.exists():
|
||||||
console.print(
|
console.print(
|
||||||
f"[red]Workspace '{ws_dir.name}' does not exist at {ws_dir}[/red]"
|
f"[red]Workspace '{ws_dir.name}' does not exist at {ws_dir}[/red]"
|
||||||
|
|
@ -771,6 +774,7 @@ def remove_workspace(
|
||||||
"""
|
"""
|
||||||
_settings, repos_dir, workspaces_dir = get_ctx_paths(ctx)
|
_settings, repos_dir, workspaces_dir = get_ctx_paths(ctx)
|
||||||
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
||||||
|
workspace = ws_dir.name
|
||||||
|
|
||||||
if not ws_dir.exists():
|
if not ws_dir.exists():
|
||||||
console.print(
|
console.print(
|
||||||
|
|
@ -871,7 +875,7 @@ def remove_workspace(
|
||||||
shutil.rmtree(wt)
|
shutil.rmtree(wt)
|
||||||
|
|
||||||
if in_tmux():
|
if in_tmux():
|
||||||
session_name = f"{ws_dir.name}|{repo.name}"
|
session_name = get_session_name(ws_dir, repo)
|
||||||
remove_session_if_exists(session_name)
|
remove_session_if_exists(session_name)
|
||||||
# Finally, remove the workspace directory itself
|
# Finally, remove the workspace directory itself
|
||||||
shutil.rmtree(ws_dir)
|
shutil.rmtree(ws_dir)
|
||||||
|
|
@ -968,6 +972,8 @@ def wip_workspace(
|
||||||
"""
|
"""
|
||||||
_settings, _repos_dir, workspaces_dir = get_ctx_paths(ctx)
|
_settings, _repos_dir, workspaces_dir = get_ctx_paths(ctx)
|
||||||
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
||||||
|
workspace = ws_dir.name
|
||||||
|
|
||||||
if not ws_dir.exists():
|
if not ws_dir.exists():
|
||||||
console.print(
|
console.print(
|
||||||
f"[red]Workspace '{ws_dir.name}' does not exist at {ws_dir}[/red]"
|
f"[red]Workspace '{ws_dir.name}' does not exist at {ws_dir}[/red]"
|
||||||
|
|
@ -1010,6 +1016,8 @@ def commit_workspace(
|
||||||
raise typer.Exit(1)
|
raise typer.Exit(1)
|
||||||
_settings, _repos_dir, workspaces_dir = get_ctx_paths(ctx)
|
_settings, _repos_dir, workspaces_dir = get_ctx_paths(ctx)
|
||||||
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
||||||
|
workspace = ws_dir.name
|
||||||
|
|
||||||
if not ws_dir.exists():
|
if not ws_dir.exists():
|
||||||
console.print(
|
console.print(
|
||||||
f"[red]Workspace '{ws_dir.name}' does not exist at {ws_dir}[/red]"
|
f"[red]Workspace '{ws_dir.name}' does not exist at {ws_dir}[/red]"
|
||||||
|
|
@ -1088,6 +1096,8 @@ def push_workspace(
|
||||||
"""
|
"""
|
||||||
_settings, _repos_dir, workspaces_dir = get_ctx_paths(ctx)
|
_settings, _repos_dir, workspaces_dir = get_ctx_paths(ctx)
|
||||||
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
||||||
|
workspace = ws_dir.name
|
||||||
|
|
||||||
if not ws_dir.exists():
|
if not ws_dir.exists():
|
||||||
console.print(
|
console.print(
|
||||||
f"[red]Workspace '{ws_dir.name}' does not exist at {ws_dir}[/red]"
|
f"[red]Workspace '{ws_dir.name}' does not exist at {ws_dir}[/red]"
|
||||||
|
|
@ -1156,6 +1166,8 @@ def status_workspace(
|
||||||
"""
|
"""
|
||||||
_settings, _repos_dir, workspaces_dir = get_ctx_paths(ctx)
|
_settings, _repos_dir, workspaces_dir = get_ctx_paths(ctx)
|
||||||
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
||||||
|
workspace = ws_dir.name
|
||||||
|
|
||||||
if not ws_dir.exists():
|
if not ws_dir.exists():
|
||||||
console.print(
|
console.print(
|
||||||
f"[red]Workspace '{ws_dir.name}' does not exist at {ws_dir}[/red]"
|
f"[red]Workspace '{ws_dir.name}' does not exist at {ws_dir}[/red]"
|
||||||
|
|
@ -1238,6 +1250,7 @@ def diff_workspace(
|
||||||
"""
|
"""
|
||||||
_settings, _repos_dir, workspaces_dir = get_ctx_paths(ctx)
|
_settings, _repos_dir, workspaces_dir = get_ctx_paths(ctx)
|
||||||
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
||||||
|
workspace = ws_dir.name
|
||||||
|
|
||||||
if not ws_dir.exists():
|
if not ws_dir.exists():
|
||||||
console.print(
|
console.print(
|
||||||
|
|
@ -1485,6 +1498,13 @@ def remove_session(session_name: str) -> None:
|
||||||
if r.returncode != 0:
|
if r.returncode != 0:
|
||||||
raise typer.Exit(r.returncode)
|
raise typer.Exit(r.returncode)
|
||||||
|
|
||||||
|
def get_session_name(ws_dir: Path, repo: Path):
|
||||||
|
session_name = f"ω|{ws_dir.name}|{repo.name}"
|
||||||
|
session_name = session_name.strip().replace(" ", "_").replace(':', '_').replace('.', '_').replace('/', '_')
|
||||||
|
return session_name
|
||||||
|
|
||||||
|
return result.stdout.decode().strip()
|
||||||
|
|
||||||
|
|
||||||
tmux_app = typer.Typer(
|
tmux_app = typer.Typer(
|
||||||
name="tmux",
|
name="tmux",
|
||||||
|
|
@ -1511,15 +1531,23 @@ def tmux_cli_attach(
|
||||||
"""
|
"""
|
||||||
_settings, _repos_dir, workspaces_dir = get_ctx_paths(ctx)
|
_settings, _repos_dir, workspaces_dir = get_ctx_paths(ctx)
|
||||||
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
||||||
|
workspace = ws_dir.name
|
||||||
|
|
||||||
if not ws_dir:
|
if not ws_dir:
|
||||||
console.print(f"[red]Workspace '{workspace}' does not exist at {ws_dir}[/red]")
|
console.print(f"[red]Workspace '{workspace}' does not exist at {ws_dir}[/red]")
|
||||||
raise typer.Exit(1)
|
raise typer.Exit(1)
|
||||||
# pick repo in workspace
|
# pick repo in workspace
|
||||||
repo = pick_repo_with_iterfzf([directory for directory in ws_dir.iterdir() if directory.is_dir()])
|
repos = [directory for directory in ws_dir.iterdir() if directory.is_dir()]
|
||||||
|
if not repos:
|
||||||
|
console.print("[red]No repos found in workspace. Add One.[/red]")
|
||||||
|
add_repo(ctx=ctx, workspace=workspace, repo_name=None)
|
||||||
|
repos = [directory for directory in ws_dir.iterdir() if directory.is_dir()]
|
||||||
|
repo = pick_repo_with_iterfzf(repos)
|
||||||
|
|
||||||
if not repo:
|
if not repo:
|
||||||
console.print("[red]No repo selected. Exiting.[/red]")
|
console.print("[red]No repo selected. Exiting.[/red]")
|
||||||
raise typer.Exit(1)
|
raise typer.Exit(1)
|
||||||
session_name = f"ω|{ws_dir.name}|{repo.name}"
|
session_name = get_session_name(ws_dir, repo)
|
||||||
console.print(f"Session name: {session_name}")
|
console.print(f"Session name: {session_name}")
|
||||||
create_if_needed_and_attach(session_name, repo, False)
|
create_if_needed_and_attach(session_name, repo, False)
|
||||||
|
|
||||||
|
|
@ -1634,3 +1662,4 @@ def attach(
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app()
|
app()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue