consistent tmux-session names (#5)
Reviewed-on: #5 Co-authored-by: Waylon S. Walker <waylon@waylonwalker.com> Co-committed-by: Waylon S. Walker <waylon@waylonwalker.com>
This commit is contained in:
parent
8cb2d1d285
commit
6d93dc8177
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)
|
||||
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
||||
workspace = ws_dir.name
|
||||
|
||||
if not ws_dir.exists():
|
||||
console.print(
|
||||
|
|
@ -569,6 +570,8 @@ def add_repo(
|
|||
"""
|
||||
_settings, repos_dir, workspaces_dir = get_ctx_paths(ctx)
|
||||
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
||||
workspace = ws_dir.name
|
||||
|
||||
if not ws_dir.exists():
|
||||
console.print(
|
||||
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)
|
||||
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
||||
workspace = ws_dir.name
|
||||
|
||||
if not ws_dir.exists():
|
||||
console.print(
|
||||
|
|
@ -871,7 +875,7 @@ def remove_workspace(
|
|||
shutil.rmtree(wt)
|
||||
|
||||
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)
|
||||
# Finally, remove the workspace directory itself
|
||||
shutil.rmtree(ws_dir)
|
||||
|
|
@ -968,6 +972,8 @@ def wip_workspace(
|
|||
"""
|
||||
_settings, _repos_dir, workspaces_dir = get_ctx_paths(ctx)
|
||||
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
||||
workspace = ws_dir.name
|
||||
|
||||
if not ws_dir.exists():
|
||||
console.print(
|
||||
f"[red]Workspace '{ws_dir.name}' does not exist at {ws_dir}[/red]"
|
||||
|
|
@ -1010,6 +1016,8 @@ def commit_workspace(
|
|||
raise typer.Exit(1)
|
||||
_settings, _repos_dir, workspaces_dir = get_ctx_paths(ctx)
|
||||
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
||||
workspace = ws_dir.name
|
||||
|
||||
if not ws_dir.exists():
|
||||
console.print(
|
||||
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)
|
||||
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
||||
workspace = ws_dir.name
|
||||
|
||||
if not ws_dir.exists():
|
||||
console.print(
|
||||
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)
|
||||
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
||||
workspace = ws_dir.name
|
||||
|
||||
if not ws_dir.exists():
|
||||
console.print(
|
||||
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)
|
||||
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
||||
workspace = ws_dir.name
|
||||
|
||||
if not ws_dir.exists():
|
||||
console.print(
|
||||
|
|
@ -1485,6 +1498,13 @@ def remove_session(session_name: str) -> None:
|
|||
if r.returncode != 0:
|
||||
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(
|
||||
name="tmux",
|
||||
|
|
@ -1511,15 +1531,23 @@ def tmux_cli_attach(
|
|||
"""
|
||||
_settings, _repos_dir, workspaces_dir = get_ctx_paths(ctx)
|
||||
ws_dir = find_workspace_dir(workspaces_dir, workspace)
|
||||
workspace = ws_dir.name
|
||||
|
||||
if not ws_dir:
|
||||
console.print(f"[red]Workspace '{workspace}' does not exist at {ws_dir}[/red]")
|
||||
raise typer.Exit(1)
|
||||
# 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:
|
||||
console.print("[red]No repo selected. Exiting.[/red]")
|
||||
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}")
|
||||
create_if_needed_and_attach(session_name, repo, False)
|
||||
|
||||
|
|
@ -1634,3 +1662,4 @@ def attach(
|
|||
|
||||
if __name__ == "__main__":
|
||||
app()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue